c-common.c (decl_attributes): Don't allow strftime formats with first_arg_num nonzero.
authorJoseph Myers <jsm28@cam.ac.uk>
Thu, 12 Oct 2000 09:28:52 +0000 (10:28 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 12 Oct 2000 09:28:52 +0000 (10:28 +0100)
* c-common.c (decl_attributes): Don't allow strftime formats with
first_arg_num nonzero.
(check_format_info): Set wanted_type and wanted_type_name to zero
before they are possibly assigned and used.

testsuite:
* gcc.dg/format-attr-1.c: New test.

From-SVN: r36845

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format-attr-1.c [new file with mode: 0644]

index 80a0937eca35681de6d0f57bb4d607517f02759f..71eae2321ef3a861b7f8bca6a0eab889a2e23132 100644 (file)
@@ -1,3 +1,10 @@
+2000-10-12  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-common.c (decl_attributes): Don't allow strftime formats with
+       first_arg_num nonzero.
+       (check_format_info): Set wanted_type and wanted_type_name to zero
+       before they are possibly assigned and used.
+
 2000-10-12  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * c-common.c (scanf_flag_specs): Add flags ' and I.
index 07384f84cabc486a8b7fd15099024b915b845539..3d3e7c209b3bcfc05f4cf8a5762f789f9d4bf8f6 100644 (file)
@@ -962,6 +962,12 @@ decl_attributes (node, attributes, prefix_attributes)
                  }
              }
 
+           if (format_type == strftime_format_type && first_arg_num != 0)
+             {
+               error ("strftime formats cannot format arguments");
+               continue;
+             }
+
            record_function_format (DECL_NAME (decl),
                                    DECL_ASSEMBLER_NAME (decl),
                                    format_type, format_num, first_arg_num);
@@ -2754,6 +2760,8 @@ check_format_info (status, info, params)
            status_warning (status, "no closing `]' for `%%[' format");
        }
 
+      wanted_type = 0;
+      wanted_type_name = 0;
       if (fki->flags & FMT_FLAG_ARG_CONVERT)
        {
          wanted_type = (fci->types[length_chars_val].type
index e7dbf2a06364fe5e1a28a1ec3ecdb560dd5ec214..369e85cfb8518b60eeed1be2ced08bd542ca8f66 100644 (file)
@@ -1,3 +1,7 @@
+2000-10-12  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.dg/format-attr-1.c: New test.
+
 2000-10-12  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.dg/c90-printf-2.c, gcc.dg/c90-scanf-2.c: Use
diff --git a/gcc/testsuite/gcc.dg/format-attr-1.c b/gcc/testsuite/gcc.dg/format-attr-1.c
new file mode 100644 (file)
index 0000000..e6ebaf2
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test for strftime format attributes: can't have first_arg_num != 0.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+extern void foo0 (const char *) __attribute__((__format__(__strftime__, 1, 0)));
+extern void foo1 (const char *, ...) __attribute__((__format__(__strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */