[Skiboot] [PATCH 2/3] Don't recognise a double hex prefix (0x0xNN) as valid.
Daniel Axtens
dja at axtens.net
Fri Feb 20 13:45:06 AEDT 2015
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 at axtens.net>
---
libc/stdlib/strtol.c | 2 --
libc/stdlib/strtoul.c | 2 --
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);
--
2.1.4
More information about the Skiboot
mailing list