From e964a55607b3cd9e45a45d3331c6f163df7519f5 Mon Sep 17 00:00:00 2001 From: Jason Thorpe Date: Sat, 18 May 2002 19:02:03 +0000 Subject: 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 --- gcc/c-format.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gcc/c-format.c') 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"); -- cgit v1.1