diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-13 03:56:31 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-13 03:56:31 +0000 |
commit | a01e62831818ed1c8c00e79991b8f34c02327127 (patch) | |
tree | 2ad7fb3cbeec9fa7cfc592bba2c3d0830a50aaeb /string.c | |
parent | acd98555b59522b8f81b8feff70964e92adb902f (diff) |
* numeric.c (rb_num_to_uint): added to check the range of arguments.
Mainly for negative value with NUM2UINT on 32bit environment.
* string.c (rb_str_concat): use rb_num_to_uint.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -2001,6 +2001,7 @@ rb_str_append(VALUE str, VALUE str2) return rb_str_buf_append(str, str2); } +int rb_num_to_uint(VALUE val, unsigned int *ret); /* * call-seq: @@ -2023,11 +2024,15 @@ rb_str_concat(VALUE str1, VALUE str2) { unsigned int lc; - if (FIXNUM_P(str2)) { - lc = FIX2UINT(str2); - } - else if (TYPE(str2) == T_BIGNUM) { - lc = NUM2UINT(str2); + if (FIXNUM_P(str2) || TYPE(str2) == T_BIGNUM) { + if (rb_num_to_uint(str2, &lc) == 0) { + } + else if (FIXNUM_P(str2)) { + rb_raise(rb_eRangeError, "%ld out of char range", FIX2LONG(str2)); + } + else { + rb_raise(rb_eRangeError, "bignum out of char range"); + } } else { return rb_str_append(str1, str2); |