[libc-commits] [libc] Add bit width length modifier to printf (PR #82461)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Mar 28 15:50:23 PDT 2024


================
@@ -169,6 +169,92 @@ 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);
----------------
michaelrj-google wrote:

this number should be marked `long long` (ends with `ll`) instead of just `long` (ends with `l`). Some platforms define `long` to only be 32 bits, but `long long` is always 64.

https://github.com/llvm/llvm-project/pull/82461


More information about the libc-commits mailing list