From 7700d6c999a86af09fa2026254b8b8fd2de992f1 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 27 Aug 2005 12:27:46 -0700 Subject: [PATCH] [svn] Fix strtoll("0x", ptr, 0) to set *ptr to position of 'x', not after it. --- src/ChangeLog | 6 ++++++ src/cmpt.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index 43784484..4ff93595 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2005-08-27 Hrvoje Niksic + + * cmpt.c (strtoll): Correctly handle strtoll("0x", ptr, 0) and + strtoll("0x", ptr, 0) -- in both cases *ptr must be + set to the position of 'x', not after it. + 2005-08-27 Hrvoje Niksic * hash.c (hash_table_map): Rename to hash_table_for_each and diff --git a/src/cmpt.c b/src/cmpt.c index a4142951..03ff3ceb 100644 --- a/src/cmpt.c +++ b/src/cmpt.c @@ -1348,6 +1348,13 @@ strtoll (const char *nptr, char **endptr, int base) { base = 16; nptr += 2; + /* "0x" must be followed by at least one hex char. If not, + return 0 and place ENDPTR on 'x'. */ + if (!ISXDIGIT (*nptr)) + { + --nptr; + goto out; + } } else if (base == 0) base = 8; @@ -1387,6 +1394,7 @@ strtoll (const char *nptr, char **endptr, int base) result = newresult; } } + out: if (endptr) *endptr = (char *) nptr; return result; -- 2.39.2