From 5ea2a1845f3393e91d6d102a8a89f339dd24f467 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 23 Nov 2020 23:09:18 -0800 Subject: fixes #1358 nni_strtou64 and nni_strtox64 could be replaced with strtoull --- src/core/strs.c | 74 --------------------------------------------------------- 1 file changed, 74 deletions(-) (limited to 'src/core/strs.c') diff --git a/src/core/strs.c b/src/core/strs.c index ce03de22..3f51e59a 100644 --- a/src/core/strs.c +++ b/src/core/strs.c @@ -173,77 +173,3 @@ nni_asprintf(char **sp, const char *fmt, ...) *sp = s; return (0); } - -int -nni_strtou64(const char *s, uint64_t *u) -{ - uint64_t v = 0; - - // Arguably we could use strtoull, but Windows doesn't conform - // to C99, and so lacks it. - - if ((s == NULL) || (*s == '\0')) { - // Require a non-empty string. - return (NNG_EINVAL); - } - while (*s) { - uint64_t last = v; - if (isdigit(*s)) { - v *= 10; - v += (*s - '0'); - } else { - return (NNG_EINVAL); - } - if (v < last) { - // Overflow! - return (NNG_EINVAL); - } - s++; - } - *u = v; - return (0); -} - -int -nni_strtox64(const char *s, uint64_t *u) -{ - uint64_t v = 0; - - // Arguably we could use strtoull, but Windows doesn't conform - // to C99, and so lacks it. - - if (s == NULL) { - return (NNG_EINVAL); - } - // Skip over 0x if present. - if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) { - s += 2; - } - if (*s == '\0') { - // Require a non-empty string. - return (NNG_EINVAL); - } - - while (*s) { - uint64_t last = v; - if (isdigit(*s)) { - v *= 16; - v += (*s - '0'); - } else if ((*s >= 'a') && (*s <= 'f')) { - v *= 16; - v += (*s - 'a') + 10; - } else if ((*s >= 'A') && (*s <= 'F')) { - v *= 16; - v += (*s - 'A') + 10; - } else { - return (NNG_EINVAL); - } - if (v < last) { - // Overflow! - return (NNG_EINVAL); - } - s++; - } - *u = v; - return (0); -} -- cgit v1.2.3-70-g09d2