You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Fix '-Wformat-overflow' FP when floats had field-width and plus prefix (#144274)
If field width is specified, the sign/space is already accounted for
within the field width, so no additional size is needed.
Fixes#143951.
---------
Co-authored-by: Aaron Ballman <[email protected]>
Copy file name to clipboardExpand all lines: clang/test/Sema/warn-format-overflow-truncation.c
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,13 @@ void call_snprintf(double d, int n, int *ptr) {
43
43
__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}}
44
44
__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}}
45
45
__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}}
46
+
__builtin_snprintf(buf, 6, "%5.1f", 9.f);
47
+
__builtin_snprintf(buf, 6, "%+5.1f", 9.f);
48
+
__builtin_snprintf(buf, 6, "% 5.1f", 9.f);
49
+
__builtin_snprintf(buf, 6, "% 5.1f", 9.f);
50
+
__builtin_snprintf(buf, 6, "%+6.1f", 9.f); // kprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 7}}
51
+
__builtin_snprintf(buf, 6, "% 6.1f", 9.f); // kprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 7}}
52
+
__builtin_snprintf(buf, 6, "% 6.1f", 9.f); // kprintf-warning {{'snprintf' will always be truncated; specified size is 6, but format string expands to at least 7}}
46
53
}
47
54
48
55
voidcall_vsnprintf(void) {
@@ -153,4 +160,11 @@ void call_sprintf(void) {
153
160
sprintf(buf, "%+.3f", 9.f); // kprintf-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
154
161
sprintf(buf, "%.0e", 9.f);
155
162
sprintf(buf, "5%.1e", 9.f); // kprintf-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 8}}
163
+
sprintf(buf, "%5.1f", 9.f);
164
+
sprintf(buf, "%+5.1f", 9.f);
165
+
sprintf(buf, "% 5.1f", 9.f);
166
+
sprintf(buf, "% 5.1f", 9.f);
167
+
sprintf(buf, "%+6.1f", 9.f); // kprintf-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
168
+
sprintf(buf, "% 6.1f", 9.f); // kprintf-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
169
+
sprintf(buf, "% 6.1f", 9.f); // kprintf-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
0 commit comments