[libc-commits] [libc] Add bit width length modifier to printf (PR #82461)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Feb 28 10:50:43 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)));
----------------
michaelrj-google wrote:
you don't need to call strlen here, just use a variable to store the result from the sprintf call for `%ju` and compare against that.
https://github.com/llvm/llvm-project/pull/82461
More information about the libc-commits
mailing list