[libc-commits] [PATCH] D156257: [libc][NFC] fix sprintf test on 32 bit systems
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jul 25 11:53:49 PDT 2023
michaelrj created this revision.
michaelrj added reviewers: lntue, mikhail.ramalho.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
michaelrj requested review of this revision.
The expected number for the max ptrdiff value was expected to be exactly
4294967296 (2**32) for 32 bit systems, when it should be
4294967295 (2**32 - 1). This also adds a second test to check for this
case on non-32 bit systems.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156257
Files:
libc/test/src/stdio/sprintf_test.cpp
Index: libc/test/src/stdio/sprintf_test.cpp
===================================================================
--- libc/test/src/stdio/sprintf_test.cpp
+++ libc/test/src/stdio/sprintf_test.cpp
@@ -122,13 +122,19 @@
EXPECT_EQ(written, 20);
ASSERT_STREQ(buff, "18446744073709551615"); // ull max
+ written = __llvm_libc::sprintf(buff, "%u", ~0);
+ if (sizeof(int) == 4) {
+ EXPECT_EQ(written, 10);
+ ASSERT_STREQ(buff, "4294967295");
+ }
+
written = __llvm_libc::sprintf(buff, "%tu", ~ptrdiff_t(0));
if (sizeof(ptrdiff_t) == 8) {
EXPECT_EQ(written, 20);
ASSERT_STREQ(buff, "18446744073709551615");
} else if (sizeof(ptrdiff_t) == 4) {
EXPECT_EQ(written, 10);
- ASSERT_STREQ(buff, "4294967296");
+ ASSERT_STREQ(buff, "4294967295");
}
written = __llvm_libc::sprintf(buff, "%lld", -9223372036854775807ll - 1ll);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156257.544065.patch
Type: text/x-patch
Size: 863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230725/ac3b8698/attachment.bin>
More information about the libc-commits
mailing list