rename -Wformat-length to -Wformat-overflow

Message ID c8dabc96-c7ba-c910-030e-ee801b233964@gmail.com
State New
Headers show

Commit Message

Martin Sebor Jan. 12, 2017, 8:31 p.m.
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

Comments

Jeff Law Jan. 12, 2017, 9:26 p.m. | #1
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.
Martin Sebor Jan. 12, 2017, 9:55 p.m. | #2
On 01/12/2017 02:26 PM, Jeff Law wrote:
> 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.


Done in r244385.

Martin

Patch hide | download patch | download mbox

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.

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt	(revision 244382)
+++ gcc/c-family/c.opt	(working copy)
@@ -520,15 +520,15 @@  Wformat-extra-args
 C ObjC C++ ObjC++ Var(warn_format_extra_args) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0)
 Warn if passing too many arguments to a function for its format string.
 
-Wformat-length
-C ObjC C++ LTO ObjC++ Warning Alias(Wformat-length=, 1, 0)
-Warn about function calls with format strings that write past the end
-of the destination region.  Same as -Wformat-length=1.
-
 Wformat-nonliteral
 C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
 Warn about format strings that are not literals.
 
+Wformat-overflow
+C ObjC C++ LTO ObjC++ Warning Alias(Wformat-overflow=, 1, 0)
+Warn about function calls with format strings that write past the end
+of the destination region.  Same as -Wformat-overflow=1.
+
 Wformat-security
 C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
 Warn about possible security problems with format functions.
@@ -554,8 +554,8 @@  Wformat=
 C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0)
 Warn about printf/scanf/strftime/strfmon format string anomalies.
 
-Wformat-length=
-C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format_length) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0)
+Wformat-overflow=
+C ObjC C++ LTO ObjC++ Joined RejectNegative UInteger Var(warn_format_overflow) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0)
 Warn about function calls with format strings that write past the end
 of the destination region.
 
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 244382)
+++ gcc/doc/invoke.texi	(working copy)
@@ -274,8 +274,8 @@  Objective-C and Objective-C++ Dialects}.
 -Wno-div-by-zero  -Wdouble-promotion  -Wduplicated-cond @gol
 -Wempty-body  -Wenum-compare  -Wno-endif-labels  -Wexpansion-to-defined @gol
 -Werror  -Werror=*  -Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
--Wno-format-contains-nul  -Wno-format-extra-args  -Wformat-length=@var{n} @gol
--Wformat-nonliteral @gol
+-Wno-format-contains-nul  -Wno-format-extra-args  @gol
+-Wformat-nonliteral -Wformat-overflow=@var{n} @gol
 -Wformat-security  -Wformat-signedness  -Wformat-truncation=@var{n} @gol
 -Wformat-y2k  -Wframe-address @gol
 -Wframe-larger-than=@var{len}  -Wno-free-nonheap-object  -Wjump-misses-init @gol
@@ -3957,10 +3957,10 @@  in the case of @code{scanf} formats, this option s
 warning if the unused arguments are all pointers, since the Single
 Unix Specification says that such unused arguments are allowed.
 
-@item -Wformat-length
-@itemx -Wformat-length=@var{level}
-@opindex Wformat-length
-@opindex Wno-format-length
+@item -Wformat-overflow
+@itemx -Wformat-overflow=@var{level}
+@opindex Wformat-overflow
+@opindex Wno-format-overflow
 Warn about calls to formatted input/output functions such as @code{sprintf}
 and @code{vsprintf} that might overflow the destination buffer.  When the
 exact number of bytes written by a format directive cannot be determined
@@ -3970,11 +3970,11 @@  will in most cases improve the accuracy of the war
 result in false positives.
 
 @table @gcctabopt
-@item -Wformat-length
-@item -Wformat-length=1
-@opindex Wformat-length
-@opindex Wno-format-length
-Level @var{1} of @option{-Wformat-length} enabled by @option{-Wformat}
+@item -Wformat-overflow
+@item -Wformat-overflow=1
+@opindex Wformat-overflow
+@opindex Wno-format-overflow
+Level @var{1} of @option{-Wformat-overflow} enabled by @option{-Wformat}
 employs a conservative approach that warns only about calls that most
 likely overflow the buffer.  At this level, numeric arguments to format
 directives with unknown values are assumed to have the value of one, and
@@ -3997,7 +3997,7 @@  void f (int a, int b)
 @}
 @end smallexample
 
-@item -Wformat-length=2
+@item -Wformat-overflow=2
 Level @var{2} warns also about calls that might overflow the destination
 buffer given an argument of sufficient length or magnitude.  At level
 @var{2}, unknown numeric arguments are assumed to have the minimum
@@ -4086,13 +4086,13 @@  compile-time it is estimated based on heuristics t
 the @var{level} argument and on optimization.  While enabling optimization
 will in most cases improve the accuracy of the warning, it may also result
 in false positives.  Except as noted otherwise, the option uses the same
-logic @option{-Wformat-length}.
+logic @option{-Wformat-overflow}.
 
 @table @gcctabopt
 @item -Wformat-truncation
 @item -Wformat-truncation=1
 @opindex Wformat-truncation
-@opindex Wno-format-length
+@opindex Wno-format-overflow
 Level @var{1} of @option{-Wformat-truncation} enabled by @option{-Wformat}
 employs a conservative approach that warns only about calls to bounded
 functions whose return value is unused and that will most likely result
@@ -8458,7 +8458,7 @@  if (snprintf (buf, "%08x", i) >= sizeof buf)
 
 The @option{-fprintf-return-value} option relies on other optimizations
 and yields best results with @option{-O2}.  It works in tandem with the
-@option{-Wformat-length} and @option{-Wformat-truncation} options.
+@option{-Wformat-overflow} and @option{-Wformat-truncation} options.
 The @option{-fprintf-return-value} option is enabled by default.
 
 @item -fno-peephole
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)
     {
       /* At level 2, or when all directives output an exact number
 	 of bytes or when their arguments were bounded by known
@@ -728,7 +728,7 @@  struct pass_sprintf_length::call_info
   /* Return the warning option corresponding to the called function.  */
   int warnopt () const
   {
-    return bounded ? OPT_Wformat_truncation_ : OPT_Wformat_length_;
+    return bounded ? OPT_Wformat_truncation_ : OPT_Wformat_overflow_;
   }
 };
 
@@ -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);
       res.range.max = (tree_fits_uhwi_p (lenrange[1])
 		       ? tree_to_uhwi (lenrange[1]) : HOST_WIDE_INT_M1U);
 
@@ -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);
 
   /* 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);
 
   /* 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;
 	  res.range.max = max_bytes_for_unknown_wc;
 	  /* The range above is good enough to issue warnings but not
 	     for value range propagation, so clear BOUNDED.  */
@@ -1756,7 +1756,7 @@  format_string (const conversion_spec &spec, tree a
 	    {
 	      bounded = false;
 
-	      if (warn_format_length > 1)
+	      if (warn_format_overflow > 1)
 		{
 		  /* Leave the minimum number of bytes the wide string
 		     converts to equal to its length and set the maximum
@@ -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))))
 	    {
 	      /* 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
       && (!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
 	      && 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)
 	      && 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))
 	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
 	      && (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))
 	navail = avail_range.min;
 
       /* Compute the offset of the first format character that is beyond
@@ -3014,7 +3014,7 @@  pass_sprintf_length::handle_gimple_call (gimple_st
 	  if (range_type == VR_RANGE)
 	    {
 	      dstsize
-		= (warn_format_length < 2
+		= (warn_format_overflow < 2
 		   ? wi::fits_uhwi_p (max) ? max.to_uhwi () : max.to_shwi ()
 		   : wi::fits_uhwi_p (min) ? min.to_uhwi () : min.to_shwi ());
 	    }
Index: gcc/testsuite/gcc.c-torture/execute/pr78622.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/pr78622.c	(revision 244382)
+++ gcc/testsuite/gcc.c-torture/execute/pr78622.c	(working copy)
@@ -1,6 +1,6 @@ 
-/* PR middle-end/78622 - [7 Regression] -Wformat-length/-fprintf-return-value
+/* PR middle-end/78622 - [7 Regression] -Wformat-overflow/-fprintf-return-value
    incorrect with overflow/wrapping
-   { dg-additional-options "-Wformat-length=2" } */
+   { dg-additional-options "-Wformat-overflow=2" } */
 
 __attribute__((noinline, noclone)) int
 foo (int x)
Index: gcc/testsuite/gcc.dg/pr78138.c
===================================================================
--- gcc/testsuite/gcc.dg/pr78138.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/pr78138.c	(working copy)
@@ -1,7 +1,7 @@ 
 /* PR middle-end/78138 - missing warnings on buffer overflow with non-constant
    source length
    { dg-do compile }
-   { dg-options "-O2 -Wformat-length" } */
+   { dg-options "-O2 -Wformat-overflow" } */
 
 char d [5];
 
Index: gcc/testsuite/gcc.dg/pr78768.c
===================================================================
--- gcc/testsuite/gcc.dg/pr78768.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/pr78768.c	(working copy)
@@ -1,14 +1,14 @@ 
-/* PR c/78768 - -Walloca-larger-than and -Wformat-length warnings disabled
+/* PR c/78768 - -Walloca-larger-than and -Wformat-overflow warnings disabled
    by -flto
   { dg-do run }
   { dg-require-effective-target lto }
-  { dg-options "-O2 -Walloca-larger-than=10 -Wformat -Wformat-length -flto" } */
+  { dg-options "-O2 -Walloca-larger-than=10 -Wformat -Wformat-overflow -flto" } */
 
 int main (void)
 {
   char *d = (char *)__builtin_alloca (12);  /* { dg-warning "argument to .alloca. is too large" } */
 
-  __builtin_sprintf (d, "%32s", "x");   /* { dg-warning "directive writing 32 bytes into a region of size 12" "-Wformat-length" { xfail *-*-* } } */
+  __builtin_sprintf (d, "%32s", "x");   /* { dg-warning "directive writing 32 bytes into a region of size 12" "-Wformat-overflow" { xfail *-*-* } } */
 
   return 0;
 }
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-4.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-4.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-4.c	(working copy)
@@ -1,7 +1,7 @@ 
 /* PR middle-end/78461 - [7 Regression] ICE: in operator+=, at
    gimple-ssa-sprintf.c:214
    Disable warnings to exercise code paths through the pass that may
-   not be exercised when the -Wformat-length option is in effect.  */
+   not be exercised when the -Wformat-overflow option is in effect.  */
 /* { dg-compile }
    { dg-options "-O2 -fdump-tree-optimized -w" } */
 
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-Wformat -Wformat-length=1 -ftrack-macro-expansion=0" } */
+/* { dg-options "-Wformat -Wformat-overflow=1 -ftrack-macro-expansion=0" } */
 /* { dg-require-effective-target int32plus } */
 
 /* When debugging, define LINE to the line number of the test case to exercise
@@ -1028,7 +1028,7 @@  void test_sprintf_chk_e_const (void)
   T (12, "%Le", 9.9999999e+99L);/* { dg-warning "terminating nul" } */
 }
 
-/* At -Wformat-length level 1 unknown numbers are assumed to have
+/* At -Wformat-overflow level 1 unknown numbers are assumed to have
    the value one, and unknown strings are assumed to have a zero
    length.  */
 
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-2.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-2.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-2.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-std=c99 -Wformat -Wformat-length=2 -ftrack-macro-expansion=0" } */
+/* { dg-options "-std=c99 -Wformat -Wformat-overflow=2 -ftrack-macro-expansion=0" } */
 
 /* When debugging, define LINE to the line number of the test case to exercise
    and avoid exercising any of the others.  The buffer and objsize macros
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-3.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-3.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-3.c	(working copy)
@@ -4,7 +4,7 @@ 
    -O2 (-ftree-vrp) is necessary for the tests involving ranges to pass,
    otherwise -O1 is sufficient.
    { dg-do compile }
-   { dg-options "-O2 -Wformat -Wformat-length=1 -ftrack-macro-expansion=0" } */
+   { dg-options "-O2 -Wformat -Wformat-overflow=1 -ftrack-macro-expansion=0" } */
 
 typedef __SIZE_TYPE__ size_t;
 
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-Wformat -Wformat-length=1 -fdiagnostics-show-caret" } */
+/* { dg-options "-Wformat -Wformat-overflow=1 -fdiagnostics-show-caret" } */
 
 extern int sprintf (char*, const char*, ...);
 
@@ -17,7 +17,7 @@  void test (void)
    sprintf (dst + 2, "1", 0);
                      ^~~
      { dg-end-multiline-output "" }
-     { dg-begin-multiline-output "-Wformat-length output" }
+     { dg-begin-multiline-output "-Wformat-overflow output" }
    sprintf (dst + 2, "1", 0);
                       ~^
      { dg-end-multiline-output "" }
@@ -35,7 +35,7 @@  void test (void)
    sprintf (dst, "1234", 0);
                  ^~~~~~
      { dg-end-multiline-output "" }
-     { dg-begin-multiline-output "-Wformat-length output" }
+     { dg-begin-multiline-output "-Wformat-overflow output" }
    sprintf (dst, "1234", 0);
                      ^
      { dg-end-multiline-output "" }
@@ -54,7 +54,7 @@  void test (void)
    sprintf (dst, "12345", 0);
                  ^~~~~~~
      { dg-end-multiline-output "" }
-     { dg-begin-multiline-output "-Wformat-length output" }
+     { dg-begin-multiline-output "-Wformat-overflow output" }
    sprintf (dst, "12345", 0);
                      ^~
      { dg-end-multiline-output "" }
@@ -68,7 +68,7 @@  void test (void)
   sprintf (dst + 2, "%-s", "1");
   /* { dg-warning "writing a terminating nul past the end of the destination" "warning" { target *-*-* } .-1 }
      { dg-message "format output 2 bytes into a destination of size 1" "note" { target *-*-* } .-2 }
-     { dg-begin-multiline-output "-Wformat-length output" }
+     { dg-begin-multiline-output "-Wformat-overflow output" }
    sprintf (dst + 2, "%-s", "1");
                       ~~~^
      { dg-end-multiline-output "" }
@@ -80,7 +80,7 @@  void test (void)
   sprintf (dst + 2, "%-s", "abcd");
   /* { dg-warning ".%-s. directive writing 4 bytes into a region of size 1" "warning" { target *-*-* } .-1 }
      { dg-message "format output 5 bytes into a destination of size 1" "note" { target *-*-* } .-2 }
-     { dg-begin-multiline-output "-Wformat-length output" }
+     { dg-begin-multiline-output "-Wformat-overflow output" }
    sprintf (dst + 2, "%-s", "abcd");
                       ^~~   ~~~~~~
      { dg-end-multiline-output "" }
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c	(working copy)
@@ -1,8 +1,8 @@ 
-/* PR middle-end/77721 - -Wformat-length not uses arg range for converted vars
+/* PR middle-end/77721 - -Wformat-overflow not uses arg range for converted vars
    Test to verify that the correct range information is made available to the
    -Wformat-lenght check to prevent warnings.  */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wformat -Wformat-length -fdump-tree-optimized" } */
+/* { dg-options "-O2 -Wformat -Wformat-overflow -fdump-tree-optimized" } */
 
 void abort (void);
 int snprintf (char*, __SIZE_TYPE__, const char*, ...);
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-7.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-7.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-7.c	(working copy)
@@ -2,7 +2,7 @@ 
    precision
    { dg-do compile }
    { dg-require-effective-target int32plus }
-   { dg-options "-Wformat-length -ftrack-macro-expansion=0" } */
+   { dg-options "-Wformat-overflow -ftrack-macro-expansion=0" } */
 
 #define INT_MAX __INT_MAX__
 #define INT_MIN (-INT_MAX - 1)
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-8.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-8.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-8.c	(working copy)
@@ -1,7 +1,7 @@ 
 /* PR middle-end/78519 - missing warning for sprintf %s with null pointer
    Also exercises null destination pointer and null format string.
    { dg-do compile }
-   { dg-options "-O2 -Wformat -Wformat-length -Wno-nonnull -ftrack-macro-expansion=0" } */
+   { dg-options "-O2 -Wformat -Wformat-overflow -Wno-nonnull -ftrack-macro-expansion=0" } */
 
 typedef __builtin_va_list va_list;
 
Index: gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-9.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-9.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-9.c	(working copy)
@@ -2,7 +2,7 @@ 
    Test to verify the correctness of ranges of output computed for floating
    point directives.
    { dg-do compile }
-   { dg-options "-O2 -Wformat -Wformat-length -ftrack-macro-expansion=0" } */
+   { dg-options "-O2 -Wformat -Wformat-overflow -ftrack-macro-expansion=0" } */
 
 typedef __builtin_va_list va_list;
 
Index: gcc/testsuite/gcc.dg/tree-ssa/pr78605.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr78605.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr78605.c	(working copy)
@@ -1,6 +1,6 @@ 
-/* PR middle-end/78605 - bogus -Wformat-length=1 with %f
+/* PR middle-end/78605 - bogus -Wformat-overflow=1 with %f
    { dg-do compile }
-   { dg-options "-O2 -Wall -Wextra -Wformat-length=1" } */
+   { dg-options "-O2 -Wall -Wextra -Wformat-overflow=1" } */
 
 char d[10];
 
Index: gcc/testsuite/gcc.dg/tree-ssa/pr78622.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr78622.c	(revision 244382)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr78622.c	(working copy)
@@ -1,7 +1,7 @@ 
-/* PR middle-end/78622 - [7 Regression] -Wformat-length/-fprintf-return-value
+/* PR middle-end/78622 - [7 Regression] -Wformat-overflow/-fprintf-return-value
    incorrect with overflow/wrapping
    { dg-do compile }
-   { dg-options "-Wformat-length=2" }
+   { dg-options "-Wformat-overflow=2" }
    The h and hh length modifiers are a C99 feature (see PR 78959).
    { dg-require-effective-target c99_runtime }  */