[libc-commits] [libc] Add bit width length modifier to printf (PR #82461)
Om Prakaash via libc-commits
libc-commits at lists.llvm.org
Thu Feb 29 15:29:15 PST 2024
================
@@ -169,6 +170,52 @@ TEST(LlvmLibcSPrintfTest, IntConv) {
EXPECT_EQ(written, 20);
ASSERT_STREQ(buff, "-9223372036854775808"); // ll min
+ written = LIBC_NAMESPACE::sprintf(buff, "%w3d", 5807);
+ EXPECT_EQ(written, 1);
+ ASSERT_STREQ(buff, "7");
+
+ written = LIBC_NAMESPACE::sprintf(buff, "%w3d", 1);
+ EXPECT_EQ(written, 1);
+ ASSERT_STREQ(buff, "1");
+
+ written = LIBC_NAMESPACE::sprintf(buff, "%w64d", 9223372036854775807l);
+ EXPECT_EQ(written, 19);
+ ASSERT_STREQ(buff, "9223372036854775807");
+
+ char format[64];
+ char uintmax[128];
+ LIBC_NAMESPACE::sprintf(format, "%%w%du", UINTMAX_WIDTH);
+ LIBC_NAMESPACE::sprintf(uintmax, "%ju", UINTMAX_MAX);
+ written = LIBC_NAMESPACE::sprintf(buff, format, UINTMAX_MAX);
+ EXPECT_EQ(written, static_cast<int>(strlen(uintmax)));
----------------
omprakaash wrote:
Oh right ! Thx. Will delete the unnecessary call.
https://github.com/llvm/llvm-project/pull/82461
More information about the libc-commits
mailing list