On 01/12/2017 01:31 PM, Martin Sebor wrote:
With the move of the snprintf truncation checking from -Wformat-length
to the dedicated -Wformat-truncation option (done in r244210),
-Wformat-length isn't as descriptive as it could and should be for
an option whose sole focus is the detection of sprintf buffer overflow.
The name is also inconsistent with the name of -Wstringop-overflow
option which focuses on detecting buffer overflow by string operations
such as strcpy or memcpy.
To make the purpose of the option clearer and its name consistent with
-Wstringop-overflow the attached patch renames -Wformat-length to
-Wformat-overflow.
Thanks
Martin
gcc-wformat-overflow.diff
gcc/c-family/ChangeLog:
* c.opt (-Wformat-length): Rename...
(-Wformat-overflow): ...to this.
gcc/ChangeLog:
* doc/invoke.texi (Warning Options): Rename -Wformat-length
to -Wformat-overflow.
* gimple-ssa-sprintf.c (pass_sprintf_length::gate): Adjust.
(min_bytes_remaining): Same.
(get_string_length): Same.
(format_string): Same.
(format_directive): Same.
(add_bytes): Same.
(pass_sprintf_length::handle_gimple_call): Same.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr78622.c: Adjust.
* gcc.dg/pr78138.c: Adjust.
* gcc.dg/pr78768.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-4.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-4.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-8.c: Adjust.
* gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Adjust.
* gcc.dg/tree-ssa/pr78605.c: Adjust.
* gcc.dg/tree-ssa/pr78622.c: Adjust.
OK with just a couple cleanups noted below.
Index: gcc/gimple-ssa-sprintf.c
===================================================================
--- gcc/gimple-ssa-sprintf.c (revision 244382)
+++ gcc/gimple-ssa-sprintf.c (working copy)
@@ -141,7 +141,7 @@ pass_sprintf_length::gate (function *)
not optimizing and the pass is being invoked early, or when
optimizing and the pass is being invoked during optimization
(i.e., "late"). */
- return ((warn_format_length > 0 || flag_printf_return_value)
+ return ((warn_format_overflow > 0 || flag_printf_return_value)
&& (optimize > 0) == fold_return_value);
}
@@ -651,7 +651,7 @@ min_bytes_remaining (unsigned HOST_WIDE_INT navail
if (HOST_WIDE_INT_MAX <= navail)
return navail;
- if (1 < warn_format_length || res.knownrange)
+ if (1 < warn_format_overflow || res.knownrange)
Go ahead and fix the operand ordering on lines you're changing. Here.
@@ -1653,7 +1653,7 @@ get_string_length (tree str)
fmtresult res;
res.range.min = (tree_fits_uhwi_p (lenrange[0])
- ? tree_to_uhwi (lenrange[0]) : 1 < warn_format_length);
+ ? tree_to_uhwi (lenrange[0]) : 1 < warn_format_overflow);
And here.
@@ -1693,12 +1693,12 @@ format_string (const conversion_spec &spec, tree a
to a "%lc" directive adjusted for precision but not field width.
6 is the longest UTF-8 sequence for a single wide character. */
const unsigned HOST_WIDE_INT max_bytes_for_unknown_wc
- = (0 <= prec ? prec : 1 < warn_format_length ? 6 : 1);
+ = (0 <= prec ? prec : 1 < warn_format_overflow ? 6 : 1);
Here.
/* The maximum number of bytes for an unknown string argument to either
a "%s" or "%ls" directive adjusted for precision but not field width. */
const unsigned HOST_WIDE_INT max_bytes_for_unknown_str
- = (0 <= prec ? prec : 1 < warn_format_length);
+ = (0 <= prec ? prec : 1 < warn_format_overflow);
Here.
/* The result is bounded unless overriddden for a non-constant string
of an unknown length. */
@@ -1718,7 +1718,7 @@ format_string (const conversion_spec &spec, tree a
is the smaller of either 0 (at level 1) or 1 (at level 2)
and WIDTH, and the maximum is MB_CUR_MAX in the selected
locale, which is unfortunately, unknown. */
- res.range.min = 1 == warn_format_length ? !nul : nul < 1;
+ res.range.min = 1 == warn_format_overflow ? !nul : nul < 1;
Here.
@@ -2038,7 +2038,7 @@ format_directive (const pass_sprintf_length::call_
|| warn_format_trunc > 1))
|| (!info.bounded
&& (spec.specifier == 's'
- || 1 < warn_format_length))))
+ || 1 < warn_format_overflow))))
Here.
{
/* The maximum directive output is longer than there is
room in the destination and the output length is either
@@ -2114,7 +2114,7 @@ format_directive (const pass_sprintf_length::call_
if (!minunder4k || fmtres.range.max > 4095)
res->under4k = false;
- if (!warned && 1 < warn_format_length
+ if (!warned && 1 < warn_format_overflow
Here.
&& (!minunder4k || fmtres.range.max > 4095))
{
/* The directive output may be longer than the maximum required
@@ -2151,7 +2151,7 @@ format_directive (const pass_sprintf_length::call_
if (!warned
&& (exceedmin
- || (1 < warn_format_length
+ || (1 < warn_format_overflow
Here.
&& res->number_chars_max > target_int_max ())))
{
/* The directive output causes the total length of output
@@ -2229,7 +2229,7 @@ add_bytes (const pass_sprintf_length::call_info &i
are bounded by the arrays they are known to refer to. */
if (!res->warned
&& (avail_range.max < nbytes
- || ((res->knownrange || 1 < warn_format_length)
+ || ((res->knownrange || 1 < warn_format_overflow)
Here.
&& avail_range.min < nbytes)))
{
/* Set NAVAIL to the number of available bytes used to decide
@@ -2237,7 +2237,7 @@ add_bytes (const pass_sprintf_length::call_info &i
warning will depend on AVAIL_RANGE. */
unsigned HOST_WIDE_INT navail = avail_range.max;
if (nbytes <= navail && avail_range.min < HOST_WIDE_INT_MAX
- && (res->knownrange || 1 < warn_format_length))
+ && (res->knownrange || 1 < warn_format_overflow))
Here.
navail = avail_range.min;
/* Compute the offset of the first format character that is beyond
@@ -2346,7 +2346,7 @@ add_bytes (const pass_sprintf_length::call_info &i
if (!res->warned
&& (exceedmin
- || (1 < warn_format_length
+ || (1 < warn_format_overflow
Here.
&& (res->number_chars_max - !end) > target_int_max ())))
{
/* The function's output exceeds INT_MAX bytes. */
@@ -2356,7 +2356,7 @@ add_bytes (const pass_sprintf_length::call_info &i
warning will depend on AVAIL_RANGE. */
unsigned HOST_WIDE_INT navail = avail_range.max;
if (nbytes <= navail && avail_range.min < HOST_WIDE_INT_MAX
- && (res->bounded || 1 < warn_format_length))
+ && (res->bounded || 1 < warn_format_overflow))
Here.