[libc-commits] [libc] a484c9b - [libc][obvious] fix errno for 32 bit long test

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Dec 22 12:02:42 PST 2022


Author: Michael Jones
Date: 2022-12-22T12:02:38-08:00
New Revision: a484c9bd2ea99c9be90cac4dfefef56d71e62efa

URL: https://github.com/llvm/llvm-project/commit/a484c9bd2ea99c9be90cac4dfefef56d71e62efa
DIFF: https://github.com/llvm/llvm-project/commit/a484c9bd2ea99c9be90cac4dfefef56d71e62efa.diff

LOG: [libc][obvious] fix errno for 32 bit long test

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

Added: 
    

Modified: 
    libc/test/src/stdlib/StrtolTest.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h
index d96b64cedd33..f240c64e52ab 100644
--- a/libc/test/src/stdlib/StrtolTest.h
+++ b/libc/test/src/stdlib/StrtolTest.h
@@ -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, ptr
diff _t(11));
 
     const char *too_big_number = "123456789012345678901";


        


More information about the libc-commits mailing list