summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-02 14:53:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-02 14:53:16 +0000
commit8097a860bc9a9fd1a3056e8594c534260e6245c9 (patch)
treef90ec4a54f6296c4319036f61277b15dbea4dcc0 /util.c
parent42492146b4533b3eebe0c38ed08c19348d4951c7 (diff)
downloadruby-8097a860bc9a9fd1a3056e8594c534260e6245c9.tar.gz
ruby-8097a860bc9a9fd1a3056e8594c534260e6245c9.tar.xz
ruby-8097a860bc9a9fd1a3056e8594c534260e6245c9.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@14854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/util.c b/util.c
index 5a4330b89..18e7bacda 100644
--- a/util.c
+++ b/util.c
@@ -117,6 +117,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
int sign = 0;
size_t len;
unsigned long ret;
+ const char *subject_found = str;
if (base == 1 || 36 < base) {
errno = EINVAL;
@@ -136,6 +137,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
}
if (str[0] == '0') {
+ subject_found = str+1;
if (base == 0 || base == 16) {
if (str[1] == 'x' || str[1] == 'X') {
b = 16;
@@ -157,8 +159,11 @@ ruby_strtoul(const char *str, char **endptr, int base)
ret = scan_digits(str, b, &len, &overflow);
+ if (0 < len)
+ subject_found = str+len;
+
if (endptr)
- *endptr = (char*)(str+len);
+ *endptr = (char*)subject_found;
if (overflow) {
errno = ERANGE;
@@ -166,7 +171,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
}
if (sign < 0) {
- ret = -(long)ret;
+ ret = -ret;
return ret;
}
else {