[clang] [Clang] Fix '-Wformat-overflow' FP when floats had field-width and plus prefix (PR #144274)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 26 04:13:40 PDT 2025


================
@@ -43,6 +43,11 @@ void call_snprintf(double d, int n, int *ptr) {
   __builtin_snprintf(node_name, sizeof(node_name), "%pOFn", ptr); // nonkprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 7}}
   __builtin_snprintf(node_name, sizeof(node_name), "12345%pOFn", ptr); // nonkprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 12}}
   __builtin_snprintf(node_name, sizeof(node_name), "123456%pOFn", ptr); // nonkprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 13}}
+  __builtin_snprintf(buf, 6, "%5.1f", 9.f);
+  __builtin_snprintf(buf, 6, "%+5.1f", 9.f);
----------------
AaronBallman wrote:

I think we don't need to add a test for + and ' ' unless that's missing coverage in general, because the diagnostic is orthogonal to the work here which is more about calculating the expected length of the resulting string.

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


More information about the cfe-commits mailing list