* util.c (ruby_strtoul): "0x", "+" and "-" is not a valid integer.

end of integer should be just after "0", the beginning, the
  beginning respectively.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-02 14:53:16 +00:00
parent 99fc557fa5
commit 1db9577184
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,9 @@
Wed Jan 2 23:50:15 2008 Tanaka Akira <akr@fsij.org>
* util.c (ruby_strtoul): "0x", "+" and "-" is not a valid integer.
end of integer should be just after "0", the beginning, the
beginning respectively.
Wed Jan 2 15:23:15 2008 Tanaka Akira <akr@fsij.org> Wed Jan 2 15:23:15 2008 Tanaka Akira <akr@fsij.org>
* util.c (ruby_strtoul): locale independent strtoul is implemented to * util.c (ruby_strtoul): locale independent strtoul is implemented to

9
util.c
View File

@ -117,6 +117,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
int sign = 0; int sign = 0;
size_t len; size_t len;
unsigned long ret; unsigned long ret;
const char *subject_found = str;
if (base == 1 || 36 < base) { if (base == 1 || 36 < base) {
errno = EINVAL; errno = EINVAL;
@ -136,6 +137,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
} }
if (str[0] == '0') { if (str[0] == '0') {
subject_found = str+1;
if (base == 0 || base == 16) { if (base == 0 || base == 16) {
if (str[1] == 'x' || str[1] == 'X') { if (str[1] == 'x' || str[1] == 'X') {
b = 16; b = 16;
@ -157,8 +159,11 @@ ruby_strtoul(const char *str, char **endptr, int base)
ret = scan_digits(str, b, &len, &overflow); ret = scan_digits(str, b, &len, &overflow);
if (0 < len)
subject_found = str+len;
if (endptr) if (endptr)
*endptr = (char*)(str+len); *endptr = (char*)subject_found;
if (overflow) { if (overflow) {
errno = ERANGE; errno = ERANGE;
@ -166,7 +171,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
} }
if (sign < 0) { if (sign < 0) {
ret = -(long)ret; ret = -ret;
return ret; return ret;
} }
else { else {