From: Rich Felker Date: Fri, 15 Jul 2011 02:11:00 +0000 (-0400) Subject: fix various bugs in new integer parser framework X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=47d027ee1a44829819c345287623fe75374893ab;hp=d3fd192523db544e6005051f224a2d7bafabedd9 fix various bugs in new integer parser framework 1. my interpretation of subject sequence definition was wrong. adjust parser to conform to the standard. 2. some code for handling tail overflow case was missing (forgot to finish writing it). 3. typo (= instead of ==) caused ERANGE to wrongly behave like EINVAL --- diff --git a/src/internal/intparse.c b/src/internal/intparse.c index 21b07b74..fd403b58 100644 --- a/src/internal/intparse.c +++ b/src/internal/intparse.c @@ -35,6 +35,7 @@ int __intparse(struct intparse *v, const void *buf, size_t n) v->cnt += n; for (; n; n--, s++) switch (v->state) { case 0: + v->err = EINVAL; v->state++; if (*s=='+' || *s=='-') { v->neg = *s=='-'; @@ -49,6 +50,7 @@ int __intparse(struct intparse *v, const void *buf, size_t n) case 2: v->state++; if ((!b || b==16) && (*s|32) == 'x') { + v->err = 0; v->base = b = 16; continue; } @@ -57,10 +59,11 @@ int __intparse(struct intparse *v, const void *buf, size_t n) case 3: firstdigit: if (digits[*s] >= b) { - v->err = EINVAL; - return 0; + n++; + goto finished; } seconddigit: + v->err = 0; v->state++; case 4: if (b==10) { @@ -92,11 +95,11 @@ int __intparse(struct intparse *v, const void *buf, size_t n) if (n && digits[*s]err = ERANGE; v->val = UINTMAX_MAX; - n--; s++; + for (; n && digits[*s]