[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] c-format: -Wformat-diag fix [PR93641]

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:55:52 GMT 2020


https://gcc.gnu.org/g:a59aa3026821ac4883198f1858984b6f78612ae6

commit a59aa3026821ac4883198f1858984b6f78612ae6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Feb 10 15:50:17 2020 +0100

    c-format: -Wformat-diag fix [PR93641]
    
    The last argument to strncasecmp is incorrect, so it matched even when
    can%' wasn't followed by t.  Also, the !ISALPHA (format_chars[1]) test
    looks pointless, format_chars[1] must be ' if strncasecmp succeeded and
    so will never be ISALPHA.
    
    2020-02-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR other/93641
            * c-format.c (check_plain): Fix up last argument of strncasecmp.
            Remove useless extra test.
    
            * gcc.dg/format/gcc_diag-11.c (test_cdiag_bad_words): Add two further
            tests.

Diff:
---
 gcc/c-family/ChangeLog                    | 6 ++++++
 gcc/c-family/c-format.c                   | 3 +--
 gcc/testsuite/ChangeLog                   | 6 ++++++
 gcc/testsuite/gcc.dg/format/gcc_diag-11.c | 2 ++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 9d9962068bb..4ba4448006a 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR other/93641
+	* c-format.c (check_plain): Fix up last argument of strncasecmp.
+	Remove useless extra test.
+
 2020-02-03  Julian Brown  <julian@codesourcery.com>
 	    Tobias Burnus  <tobias@codesourcery.com>
 
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 487edc7a5d7..51fd31e4d97 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -3270,8 +3270,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 			       "quoted %qs directive in format; "
 			       "use %qs instead", "%s", "%qs");
       else if (format_chars - orig_format_chars > 2
-	       && !strncasecmp (format_chars - 3, "can%'t", 5)
-	       && !ISALPHA (format_chars[1]))
+	       && !strncasecmp (format_chars - 3, "can%'t", 6))
 	format_warning_substr (format_string_loc,
 			       format_string_cst,
 			       fmtchrpos - 3, fmtchrpos + 3, opt,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0ede9604611..b3966ec6d90 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR other/93641
+	* gcc.dg/format/gcc_diag-11.c (test_cdiag_bad_words): Add two further
+	tests.
+
 2020-02-10  Feng Xue  <fxue@os.amperecomputing.com>
 
 	PR ipa/93203
diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-11.c b/gcc/testsuite/gcc.dg/format/gcc_diag-11.c
index a976c7aa519..262e7e5ff99 100644
--- a/gcc/testsuite/gcc.dg/format/gcc_diag-11.c
+++ b/gcc/testsuite/gcc.dg/format/gcc_diag-11.c
@@ -400,6 +400,8 @@ void test_cdiag_bad_words (tree t, gimple *gc)
   cdiag ("you can't do that"); /* { dg-warning "contraction 'can't' in format" } */
   cdiag ("you can%'t do that");/* { dg-warning "contraction 'can%'t' in format" } */
   cdiag ("Can%'t touch this.");/* { dg-warning "contraction 'Can%'t' in format" } */
+  cdiag ("can%'");
+  cdiag ("can%' whatever");
   cdiag ("on the commandline");/* { dg-warning "misspelled term 'commandline' in format; use 'command line' instead" } */
   cdiag ("command line option");/* { dg-warning "misspelled term 'command line option' in format; use 'command-line option' instead" } */
   cdiag ("it mustn't be");     /* { dg-warning "contraction 'mustn't' in format" } */


More information about the Gcc-cvs mailing list