Skip to content

Commit

Permalink
* pack.c (pack_pack): template f should not accept non float
Browse files Browse the repository at this point in the history
  values.  [ruby-dev:37656]

* object.c (rb_to_float): new function to type check floats.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 29, 2008
1 parent 6bbd76a commit ad00464
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Mon Dec 29 22:37:57 2008 Yukihiro Matsumoto <[email protected]>

* pack.c (pack_pack): template f should not accept non float
values. [ruby-dev:37656]

* object.c (rb_to_float): new function to type check floats.

Mon Dec 29 22:27:11 2008 Yukihiro Matsumoto <[email protected]>

* random.c (rb_f_rand): type check simplified. strings are no
Expand Down
1 change: 1 addition & 0 deletions include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ VALUE rb_check_convert_type(VALUE,int,const char*,const char*);
VALUE rb_check_to_integer(VALUE, const char *);
VALUE rb_to_int(VALUE);
VALUE rb_Integer(VALUE);
VALUE rb_to_float(VALUE);
VALUE rb_Float(VALUE);
VALUE rb_String(VALUE);
VALUE rb_Array(VALUE);
Expand Down
15 changes: 15 additions & 0 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,21 @@ rb_f_float(VALUE obj, VALUE arg)
return rb_Float(arg);
}

VALUE
rb_to_float(VALUE val)
{
VALUE v;

if (TYPE(val) == T_FLOAT) return val;
v = convert_type(val, "Float", "to_f", Qtrue);
if (TYPE(v) != T_FLOAT) {
const char *cname = rb_obj_classname(val);
rb_raise(rb_eTypeError, "can't convert %s to Float (%s#to_f gives %s)",
cname, cname, rb_obj_classname(v));
}
return v;
}

double
rb_num2dbl(VALUE val)
{
Expand Down
2 changes: 1 addition & 1 deletion pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ pack_pack(VALUE ary, VALUE fmt)
float f;

from = NEXTFROM;
f = RFLOAT_VALUE(rb_Float(from));
f = RFLOAT_VALUE(rb_to_float(from));
rb_str_buf_cat(res, (char*)&f, sizeof(float));
}
break;
Expand Down

0 comments on commit ad00464

Please sign in to comment.