diff options
author | Trond Norbye <trond.norbye@gmail.com> | 2011-09-03 05:29:10 +0200 |
---|---|---|
committer | Trond Norbye <trond.norbye@gmail.com> | 2011-09-03 05:29:10 +0200 |
commit | 51c8f31fc709d06c479de88bdc5e14e757faabc5 (patch) | |
tree | 648026fd064ad7505785a28610361cba14bfe796 /util.c | |
parent | 9d871c0e0c95745726f205f38faaf4d6529fd5e8 (diff) | |
download | memcached-51c8f31fc709d06c479de88bdc5e14e757faabc5.tar.gz |
Issue 221: Increment treats leading spaces as 0
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -17,8 +17,10 @@ bool safe_strtoull(const char *str, uint64_t *out) { *out = 0; char *endptr; unsigned long long ull = strtoull(str, &endptr, 10); - if (errno == ERANGE) + if ((errno == ERANGE) || (str == endptr)) { return false; + } + if (xisspace(*endptr) || (*endptr == '\0' && endptr != str)) { if ((long long) ull < 0) { /* only check for negative signs in the uncommon case when @@ -40,8 +42,10 @@ bool safe_strtoll(const char *str, int64_t *out) { *out = 0; char *endptr; long long ll = strtoll(str, &endptr, 10); - if (errno == ERANGE) + if ((errno == ERANGE) || (str == endptr)) { return false; + } + if (xisspace(*endptr) || (*endptr == '\0' && endptr != str)) { *out = ll; return true; @@ -58,7 +62,7 @@ bool safe_strtoul(const char *str, uint32_t *out) { errno = 0; l = strtoul(str, &endptr, 10); - if (errno == ERANGE) { + if ((errno == ERANGE) || (str == endptr)) { return false; } @@ -84,8 +88,10 @@ bool safe_strtol(const char *str, int32_t *out) { *out = 0; char *endptr; long l = strtol(str, &endptr, 10); - if (errno == ERANGE) + if ((errno == ERANGE) || (str == endptr)) { return false; + } + if (xisspace(*endptr) || (*endptr == '\0' && endptr != str)) { *out = l; return true; |