[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 21 09:57:57 PST 2024


================
@@ -177,6 +177,8 @@ template <typename ArgProvider> class Parser {
           WRITE_ARG_VAL_SIMPLEST(section.conv_val_raw, long long, conv_index);
           break;
         case (LengthModifier::j):
+        case (LengthModifier::w):
----------------
michaelrj-google wrote:

I'm not sure that this is correct. We should probably have `w` and `wf` request an argument of the smallest type that will fit, but is at least the size of an int.

The reason we want to roughly match the int size is because these arguments may be packed together in memory and so we may get incorrect behavior if we request too many bits for a given argument. We can assume nothing's smaller than an int though because va_args automatically promotes to int if the argument is smaller.

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


More information about the libc-commits mailing list