summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorTrond Norbye <trond.norbye@gmail.com>2011-09-03 05:29:10 +0200
committerTrond Norbye <trond.norbye@gmail.com>2011-09-03 05:29:10 +0200
commit51c8f31fc709d06c479de88bdc5e14e757faabc5 (patch)
tree648026fd064ad7505785a28610361cba14bfe796 /util.c
parent9d871c0e0c95745726f205f38faaf4d6529fd5e8 (diff)
downloadmemcached-51c8f31fc709d06c479de88bdc5e14e757faabc5.tar.gz
Issue 221: Increment treats leading spaces as 0
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/util.c b/util.c
index 95f51fa..cbb0352 100644
--- a/util.c
+++ b/util.c
@@ -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;