diff options
author | Daniel Axtens <dja@axtens.net> | 2015-02-20 13:45:06 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-02-23 13:35:50 +1100 |
commit | e4f5a453bb4e8b9ee3820c0f495beff417a867de (patch) | |
tree | 0aa2796bbd84b9f1b640e0a0f01e6f1a24c36afa /libc | |
parent | e4ce915ea0631f5b17082aa8c70079b0e9dc33af (diff) | |
download | skiboot-e4f5a453bb4e8b9ee3820c0f495beff417a867de.zip skiboot-e4f5a453bb4e8b9ee3820c0f495beff417a867de.tar.gz skiboot-e4f5a453bb4e8b9ee3820c0f495beff417a867de.tar.bz2 |
Don't recognise a double hex prefix (0x0xNN) as valid.
When autodetecting the base, the code would strip hex prefixes twice.
Now the string is not modified in the detection stage.
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc')
-rw-r--r-- | libc/stdlib/strtol.c | 2 | ||||
-rw-r--r-- | libc/stdlib/strtoul.c | 2 | ||||
-rw-r--r-- | libc/test/run-stdlib.c | 7 |
3 files changed, 3 insertions, 8 deletions
diff --git a/libc/stdlib/strtol.c b/libc/stdlib/strtol.c index 474597a..e6d4da3 100644 --- a/libc/stdlib/strtol.c +++ b/libc/stdlib/strtol.c @@ -53,8 +53,6 @@ long int strtol(const char *S, char **PTR,int BASE) if ((**PTR == '0') && (*((*PTR)+1) == 'x')) { BASE = 16; - (*PTR)++; - (*PTR)++; } else { diff --git a/libc/stdlib/strtoul.c b/libc/stdlib/strtoul.c index 754e7db..8472668 100644 --- a/libc/stdlib/strtoul.c +++ b/libc/stdlib/strtoul.c @@ -46,8 +46,6 @@ unsigned long int strtoul(const char *S, char **PTR,int BASE) if ((**PTR == '0') && (*((*PTR)+1) == 'x')) { BASE = 16; - (*PTR)++; - (*PTR)++; } else { diff --git a/libc/test/run-stdlib.c b/libc/test/run-stdlib.c index bb64790..98c79b7 100644 --- a/libc/test/run-stdlib.c +++ b/libc/test/run-stdlib.c @@ -41,8 +41,8 @@ int main(void) /* our atoi recognises hex! */ assert(atoi("0x800") == 0x800); - /* Really weird hex! */ - assert(atoi("0x0x800") == 0x800); + /* But not with a duplicate prefix */ + assert(atoi("0x0x800") == 0); /* atol - ensure it recognises longs */ assert(atol("2147483648") == 2147483648); @@ -73,8 +73,7 @@ int main(void) /* strtoul - autodetection of base */ assert(strtoul(" 123456", NULL, 0) == 123456); assert(strtoul("0x800", NULL, 0) == 0x800); - /* Again, really weird hex */ - assert(strtoul("0x0x800", NULL, 0) == 0x800); + assert(strtoul("0x0x800", NULL, 0) == 0); /* strtoul - weird/invalid bases */ assert(strtoul("z", NULL, -1) == 0); |