Skip to content

Commit 0f8b7b7

Browse files
mshimozatoTTdanieldegrasse
authored andcommitted
stdlib : strtoll : fix strtoll overflow handling with unsigned accumulator
ensure correct assignment of overflow values to unsigned accumulator Signed-off-by: Mai Shimozato <mshimozato@tenstorrent.com>
1 parent aa8b259 commit 0f8b7b7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/libc/minimal/source/stdlib/strtoll.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ long long strtoll(const char *nptr, char **endptr, register int base)
114114
}
115115

116116
if (any < 0) {
117-
acc = neg ? LLONG_MIN : LLONG_MAX;
117+
if (neg) {
118+
acc = (unsigned long long)(-(LLONG_MIN + 1)) + 1;
119+
} else {
120+
acc = LLONG_MAX;
121+
}
118122
errno = ERANGE;
119123
} else if (neg) {
120124
acc = -acc;

0 commit comments

Comments
 (0)