[libc][NFC] make atoi undefined cases match std
authorMichael Jones <michaelrj@google.com>
Mon, 19 Dec 2022 21:35:45 +0000 (13:35 -0800)
committerMichael Jones <michaelrj@google.com>
Tue, 20 Dec 2022 18:21:25 +0000 (10:21 -0800)
commitce4d6717f85eeddd0b374d2829f46548972c5d4e
treecfe6cde47921fc06f7281cf1194f220491a7e203
parent407b18820c40db83729d97a2877dd63008d5ff92
[libc][NFC] make atoi undefined cases match std

The standard describes atoi as:

"equivalent to atoi: (int)strtol(nptr, (char **)NULL, 10)"

Previously, our behavior was slightly different on numbers larger than
INT_MAX, but this patch changes it to just do the cast instead. Both of
these are valid since the standard says

"If the value of the result cannot be represented, the
behavior is undefined."

But matching existing behavior makes differential fuzzing easier.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140350
libc/src/stdlib/atoi.cpp
libc/test/src/stdlib/AtoiTest.h