This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: "format not a string literal"


 > From: Ulrich Drepper <drepper@cygnus.com>
 >  
 > Its must be a recent addition since I haven't seen it before.  The
 > current CVS gcc emits
 >  
 >         warning: format not a string literal, argument types not
 > 	checked
 >  
 > Please remove this again.  This warning is useless and it increases
 > the noice level.  If some call to a function marked with the 'printf'
 > or `scanf' attribute has no string literal in this position this can
 > very well be intended.  E.g., in the glibc implementation this happens
 > all over the place for functions like
 >  
 > __STDIO_INLINE int
 > vprintf (__const char *__restrict __fmt, _G_va_list __arg) __THROW
 > {
 >   return vfprintf (stdout, __fmt, __arg);
 > }
 >  
 >  
 > This now provokes a warning.  This is really bad since there is no way
 > to prevent this.
 > -- 


	Does this gcc patch help out?  I'd be interested to know if
any other false positives remain.

		--Kaveh

--- cvs-egcs/egcs/gcc/c-common.c	Sun Oct 10 07:42:44 1999
+++ egcs-CVS19991011/gcc/c-common.c	Mon Oct 11 13:42:38 1999
@@ -1491,7 +1491,11 @@ check_format_info (info, params)
     {
       /* The user may get multiple warnings if the supplied argument
 	 isn't even a string pointer.  */
-      warning ("format not a string literal, argument types not checked");
+      /* Functions taking a va_list normally pass a non-literal format
+	 string.  These function typically are declared with
+	 first_arg_num == 0, so avoid warning in those cases.  */
+      if (info->first_arg_num != 0)
+	warning ("format not a string literal, argument types not checked");
       return;
     }
   format_tree = TREE_OPERAND (format_tree, 0);
@@ -1499,7 +1503,11 @@ check_format_info (info, params)
     {
       /* The user may get multiple warnings if the supplied argument
 	 isn't even a string pointer.  */
-      warning ("format not a string literal, argument types not checked");
+      /* Functions taking a va_list normally pass a non-literal format
+	 string.  These function typically are declared with
+	 first_arg_num == 0, so avoid warning in those cases.  */
+      if (info->first_arg_num != 0)
+	warning ("format not a string literal, argument types not checked");
       return;
     }
   format_chars = TREE_STRING_POINTER (format_tree);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]