From b10ad7eb5795f116e6ad623d0a73d57491d0f271 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 21 Jan 2019 22:25:19 -0500 Subject: [PATCH] roken: strtoll.c negation is a no-op on unsigned integer strtoll() returns a signed long long not an unsigned long long. When applying the negation for negatives the value must be cast from unsigned to signed and then stored in a signed variable before returning it. Change-Id: If568afd2509d27c7bf206ca59d32ca150cb34857 --- lib/roken/strtoll.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/roken/strtoll.c b/lib/roken/strtoll.c index 1be876131..f5ba9338b 100644 --- a/lib/roken/strtoll.c +++ b/lib/roken/strtoll.c @@ -57,6 +57,7 @@ strtoll(const char * nptr, char ** endptr, int base) { const char *s; unsigned long long acc; + long long ret = 0; char c; unsigned long long cutoff; int neg, any, cutlim; @@ -135,15 +136,14 @@ strtoll(const char * nptr, char ** endptr, int base) } } if (any < 0) { - acc = neg ? LLONG_MIN : LLONG_MAX; + ret = neg ? LLONG_MIN : LLONG_MAX; errno = ERANGE; } else if (!any) { noconv: errno = EINVAL; } else if (neg) - acc = -acc; + ret = -(long long)acc; if (endptr != NULL) *endptr = (char *)(any ? s - 1 : nptr); - return (acc); + return ret; } - -- 2.11.4.GIT