+2000-12-07 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * c-common.c (check_format_info): Warn for non-constant format
+ strings with strftime formats if -Wformat-nonliteral. Where the
+ format can convert arguments, if the format is not a string
+ literal and there are no arguments to the format, give a different
+ warning message from the general non-string-literal case.
+
2000-12-07 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (format_wanted_type): Add reading_from_flag.
/* Functions taking a va_list normally pass a non-literal format
string. These functions typically are declared with
first_arg_num == 0, so avoid warning in those cases. */
- if (info->first_arg_num != 0 && warn_format_nonliteral)
- status_warning (status, "format not a string literal, argument types not checked");
+ if (!(format_types[info->format_type].flags & FMT_FLAG_ARG_CONVERT))
+ {
+ /* For strftime-like formats, warn for not checking the format
+ string; but there are no arguments to check. */
+ if (warn_format_nonliteral)
+ status_warning (status, "format not a string literal, format string not checked");
+ }
+ else if (info->first_arg_num != 0)
+ {
+ /* If there are no arguments for the format at all, we may have
+ printf (foo) which is likely to be a security hole. */
+ while (arg_num + 1 < info->first_arg_num)
+ {
+ if (params == 0)
+ break;
+ params = TREE_CHAIN (params);
+ ++arg_num;
+ }
+ if (params == 0 && warn_format_nonliteral)
+ status_warning (status, "format not a string literal and no format arguments");
+ else if (warn_format_nonliteral)
+ status_warning (status, "format not a string literal, argument types not checked");
+ }
}
/* If there were extra arguments to the format, normally warn. However,
--- /dev/null
+/* Test for warnings for non-string-literal formats. Test for strftime formats. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct tm;
+
+extern size_t strftime (char *, size_t, const char *, const struct tm *);
+
+void
+foo (char *s, size_t m, const struct tm *tp, char *fmt)
+{
+ strftime (s, m, fmt, tp); /* { dg-warning "format string" "non-literal" } */
+}