diff options
author | Jason Thorpe <thorpej@wasabisystems.com> | 2002-05-18 19:02:03 +0000 |
---|---|---|
committer | Jason Thorpe <thorpej@gcc.gnu.org> | 2002-05-18 19:02:03 +0000 |
commit | e964a55607b3cd9e45a45d3331c6f163df7519f5 (patch) | |
tree | c6b8df55dea21cfdbf9d6f73c35e548d165992b2 | |
parent | d92b44865fab81d50fc2db997387f92448d7611a (diff) | |
download | gcc-e964a55607b3cd9e45a45d3331c6f163df7519f5.zip gcc-e964a55607b3cd9e45a45d3331c6f163df7519f5.tar.gz gcc-e964a55607b3cd9e45a45d3331c6f163df7519f5.tar.bz2 |
c-common.c (c_common_post_options): Warn if -Wformat-zero-length is used without -Wformat.
* c-common.c (c_common_post_options): Warn if -Wformat-zero-length
is used without -Wformat.
* c-common.h (warn_format_zero_length): Declare extern.
* c-decl.c (warn_options): Add "format-zero-length".
* c-format.c (warn_format_zero_length): Declare.
(set_Wformat): Set warn_format_zero_length for -Wformat.
(check_format_info): Only warn about zero-length formats if
warn_format_zero_length is true. Include the format type
name in the warning message.
* doc/invoke.texi: Document -Wformat-zero-length.
* testsuite/gcc.dg/format/zero-length-1.c: New test.
From-SVN: r53592
-rw-r--r-- | gcc/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/c-common.c | 2 | ||||
-rw-r--r-- | gcc/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-decl.c | 1 | ||||
-rw-r--r-- | gcc/c-format.c | 10 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/zero-length-1.c | 15 |
7 files changed, 52 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8e3b2c0..9951dc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2002-05-18 Jason Thorpe <thorpej@wasabisystems.com> + + * c-common.c (c_common_post_options): Warn if -Wformat-zero-length + is used without -Wformat. + * c-common.h (warn_format_zero_length): Declare extern. + * c-decl.c (warn_options): Add "format-zero-length". + * c-format.c (warn_format_zero_length): Declare. + (set_Wformat): Set warn_format_zero_length for -Wformat. + (check_format_info): Only warn about zero-length formats if + warn_format_zero_length is true. Include the format type + name in the warning message. + * doc/invoke.texi: Document -Wformat-zero-length. + * testsuite/gcc.dg/format/zero-length-1.c: New test. + 2002-05-18 Kazu Hirata <kazu@cs.umass.edu> * timevar.c: Fix formatting. diff --git a/gcc/c-common.c b/gcc/c-common.c index 5a87899..d851c27 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -4311,6 +4311,8 @@ c_common_post_options () warning ("-Wformat-y2k ignored without -Wformat"); if (warn_format_extra_args && !warn_format) warning ("-Wformat-extra-args ignored without -Wformat"); + if (warn_format_zero_length && !warn_format) + warning ("-Wformat-zero-length ignored without -Wformat"); if (warn_format_nonliteral && !warn_format) warning ("-Wformat-nonliteral ignored without -Wformat"); if (warn_format_security && !warn_format) diff --git a/gcc/c-common.h b/gcc/c-common.h index 7c5c30d..8666095 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -414,6 +414,10 @@ extern int warn_format_y2k; extern int warn_format_extra_args; +/* Warn about zero-length formats. */ + +extern int warn_format_zero_length; + /* Warn about non-literal format arguments. */ extern int warn_format_nonliteral; diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 854cd73..8825db1 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -474,6 +474,7 @@ c_decode_option (argc, argv) { "div-by-zero", &warn_div_by_zero }, { "float-equal", &warn_float_equal }, { "format-extra-args", &warn_format_extra_args }, + { "format-zero-length", &warn_format_zero_length }, { "format-nonliteral", &warn_format_nonliteral }, { "format-security", &warn_format_security }, { "format-y2k", &warn_format_y2k }, diff --git a/gcc/c-format.c b/gcc/c-format.c index 470ccf7..dc73f4d 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -44,6 +44,10 @@ int warn_format_y2k; int warn_format_extra_args; +/* Warn about zero-length formats. */ + +int warn_format_zero_length; + /* Warn about non-literal format arguments. */ int warn_format_nonliteral; @@ -61,6 +65,7 @@ set_Wformat (setting) warn_format = setting; warn_format_y2k = setting; warn_format_extra_args = setting; + warn_format_zero_length = setting; if (setting != 1) { warn_format_nonliteral = setting; @@ -1361,8 +1366,9 @@ check_format_info (status, info, params) && res.number_other == 0 && warn_format_extra_args) status_warning (status, "unused arguments in $-style format"); if (res.number_empty > 0 && res.number_non_literal == 0 - && res.number_other == 0) - status_warning (status, "zero-length format string"); + && res.number_other == 0 && warn_format_zero_length) + status_warning (status, "zero-length %s format string", + format_types[info->format_type].name); if (res.number_wide > 0) status_warning (status, "format is a wide character string"); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1190c97..855fcd9 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1844,9 +1844,9 @@ Options,,Options Controlling C Dialect}. @option{-Wformat} is included in @option{-Wall}. For more control over some aspects of format checking, the options @option{-Wno-format-y2k}, -@option{-Wno-format-extra-args}, @option{-Wformat-nonliteral}, -@option{-Wformat-security} and @option{-Wformat=2} are available, but are -not included in @option{-Wall}. +@option{-Wno-format-extra-args}, @option{-Wno-format-zero-length}, +@option{-Wformat-nonliteral}, @option{-Wformat-security}, and +@option{-Wformat=2} are available, but are not included in @option{-Wall}. @item -Wno-format-y2k @opindex Wno-format-y2k @@ -1867,6 +1867,11 @@ in the case of @code{scanf} formats, this option will suppress the warning if the unused arguments are all pointers, since the Single Unix Specification says that such unused arguments are allowed. +@item -Wno-format-zero-length +@opindex Wno-format-zero-length +If @option{-Wformat} is specified, do not warn about zero-length formats. +The C standard specifies that zero-length formats are allowed. + @item -Wformat-nonliteral @opindex Wformat-nonliteral If @option{-Wformat} is specified, also warn if the format string is not a diff --git a/gcc/testsuite/gcc.dg/format/zero-length-1.c b/gcc/testsuite/gcc.dg/format/zero-length-1.c new file mode 100644 index 0000000..4cf37f3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/zero-length-1.c @@ -0,0 +1,15 @@ +/* Test the -Wno-format-zero-length option, which suppresses warnings + about zero-length formats. */ +/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-format-zero-length" } */ + +#include "format.h" + +void +foo (void) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */ + /* Zero-length format strings are allowed. */ + printf (""); +} |