Skip to content

Commit

Permalink
[libc][obvious] fix errno for 32 bit long test
Browse files Browse the repository at this point in the history
one of the tests in StrtolTest.h is intended to detect that 32 bit longs
are handled correctly, but it wasn't using the correct value for errno
causing failures.

Differential Revision: https://reviews.llvm.org/D140577
  • Loading branch information
michaelrj-google committed Dec 22, 2022
1 parent 81d1b61 commit a484c9b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libc/test/src/stdlib/StrtolTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ struct StrtoTest : public __llvm_libc::testing::Test {
// wide, strtol will return LONG_MAX.
const char *bigger_number = "12345678900";
errno = 0;
ASSERT_EQ(func(bigger_number, &str_end, 10),
((sizeof(ReturnT) < 8) ? T_MAX : ReturnT(12345678900)));
ASSERT_EQ(errno, 0);
if constexpr (sizeof(ReturnT) < 8) {
ASSERT_EQ(func(bigger_number, &str_end, 10), T_MAX);
ASSERT_EQ(errno, ERANGE);
} else {
ASSERT_EQ(func(bigger_number, &str_end, 10), ReturnT(12345678900));
ASSERT_EQ(errno, 0);
}
EXPECT_EQ(str_end - bigger_number, ptrdiff_t(11));

const char *too_big_number = "123456789012345678901";
Expand Down

0 comments on commit a484c9b

Please sign in to comment.