Skip to content

Commit

Permalink
* util.c (ruby_strtod): Float("1e") should fail. [ruby-core:7330]
Browse files Browse the repository at this point in the history
* pack.c (EXTEND32): unpack("l") did not work where sizeof(long) != 4.
  [ruby-talk:180024]

* pack.c (pack_unpack): fixed integer overflow on template "w".
  [ruby-talk:180126]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ocean committed Feb 17, 2006
1 parent dd0fa83 commit d0a3c64
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Fri Feb 17 11:20:53 2006 Hirokazu Yamamoto <[email protected]>

* util.c (ruby_strtod): Float("1e") should fail. [ruby-core:7330]

* pack.c (EXTEND32): unpack("l") did not work where sizeof(long) != 4.
[ruby-talk:180024]

* pack.c (pack_unpack): fixed integer overflow on template "w".
[ruby-talk:180126]

Fri Feb 17 09:39:29 2006 Yukihiro Matsumoto <[email protected]>

* eval.c (rb_thread_wait_for): sleep should always sleep for
Expand Down
6 changes: 3 additions & 3 deletions pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ num2i32(VALUE x)
return 0; /* not reached */
}

#if SIZEOF_LONG == SIZE32 || SIZEOF_INT == SIZE32
#if SIZEOF_LONG == SIZE32
# define EXTEND32(x)
#else
/* invariant in modulo 1<<31 */
# define EXTEND32(x) do {if (!natint) {(x) = (I32)(((1<<31)-1-(x))^~(~0<<31));}} while(0)
# define EXTEND32(x) do { if (!natint) {(x) = (((1L<<31)-1-(x))^~(~0L<<31));}} while(0)
#endif
#if SIZEOF_SHORT == SIZE16
# define EXTEND16(x)
Expand Down Expand Up @@ -1937,7 +1937,7 @@ pack_unpack(VALUE str, VALUE fmt)
case 'w':
{
unsigned long ul = 0;
unsigned long ulmask = 0xfeL << ((sizeof(unsigned long) - 1) * 8);
unsigned long ulmask = 0xfeUL << ((sizeof(unsigned long) - 1) * 8);

while (len > 0 && s < send) {
ul <<= 7;
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_strtod
assert_raise(ArgumentError){Float("+.")}
assert_raise(ArgumentError){Float("-")}
assert_raise(ArgumentError){Float("-.")}
assert_raise(ArgumentError){Float("1e")}
# add expected behaviour here.
end
end
3 changes: 3 additions & 0 deletions test/ruby/test_pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def test_pack

$x = [-1073741825]
assert_equal($x, $x.pack("q").unpack("q"))

$x = [-1]
assert_equal($x, $x.pack("l").unpack("l"))
end

def test_pack_N
Expand Down
12 changes: 9 additions & 3 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,15 @@ ruby_strtod(
}
expSign = FALSE;
}
while (ISDIGIT(*p)) {
exp = exp * 10 + (*p - '0');
p += 1;
if (ISDIGIT(*p)) {
do {
exp = exp * 10 + (*p - '0');
p += 1;
}
while (ISDIGIT(*p));
}
else {
p = pExp;
}
}
if (expSign) {
Expand Down

0 comments on commit d0a3c64

Please sign in to comment.