This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

eliminate warnings in printcmd.c


This patch eliminates warnings whereby the format string is not a
string literal and GCC cannot check it at compile-time.  I don't
expect this patch to be tremendously popular, but my hope is that it
will stimulate some discussion on how to really fix it :-)

Cheers, Ben

2004-12-10  Ben Elliston  <bje@au.ibm.com>

	* defs.h (printf_filtered_nonliteral): New extern function.
	* utils.c (printf_filtered_nonliteral): Implement it.
	* printcmd.c (printf_command): Use it where the format string is
	not a string literal.

Index: defs.h
===================================================================
RCS file: /home/bje/src-cvs/src/gdb/defs.h,v
retrieving revision 1.175
diff -u -p -u -r1.175 defs.h
--- defs.h	13 Nov 2004 17:00:04 -0000	1.175
+++ defs.h	10 Dec 2004 04:02:27 -0000
@@ -476,6 +476,8 @@ extern void fprintfi_filtered (int, stru
 
 extern void printf_filtered (const char *, ...) ATTR_FORMAT (printf, 1, 2);
 
+extern void printf_filtered_nonliteral (const char *, ...);
+
 extern void printfi_filtered (int, const char *, ...) ATTR_FORMAT (printf, 2, 3);
 
 extern void vprintf_unfiltered (const char *, va_list) ATTR_FORMAT (printf, 1, 0);
Index: utils.c
===================================================================
RCS file: /home/bje/src-cvs/src/gdb/utils.c,v
retrieving revision 1.139
diff -u -p -u -r1.139 utils.c
--- utils.c	9 Nov 2004 00:59:03 -0000	1.139
+++ utils.c	10 Dec 2004 04:02:29 -0000
@@ -2292,6 +2292,14 @@ printf_filtered (const char *format, ...
   va_end (args);
 }
 
+void
+printf_filtered_nonliteral (const char *format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  vfprintf_filtered (gdb_stdout, format, args);
+  va_end (args);
+}
 
 void
 printf_unfiltered (const char *format, ...)
Index: printcmd.c
===================================================================
RCS file: /home/bje/src-cvs/src/gdb/printcmd.c,v
retrieving revision 1.81
diff -u -p -u -r1.81 printcmd.c
--- printcmd.c	12 Nov 2004 21:45:07 -0000	1.81
+++ printcmd.c	10 Dec 2004 04:02:28 -0000
@@ -1946,20 +1946,20 @@ printf_command (char *arg, int from_tty)
 		read_memory (tem, str, j);
 	      str[j] = 0;
 
-	      printf_filtered (current_substring, str);
+	      printf_filtered_nonliteral (current_substring, str);
 	    }
 	    break;
 	  case double_arg:
 	    {
 	      double val = value_as_double (val_args[i]);
-	      printf_filtered (current_substring, val);
+	      printf_filtered_nonliteral (current_substring, val);
 	      break;
 	    }
 	  case long_long_arg:
 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
 	    {
 	      long long val = value_as_long (val_args[i]);
-	      printf_filtered (current_substring, val);
+	      printf_filtered_nonliteral (current_substring, val);
 	      break;
 	    }
 #else
@@ -1969,7 +1969,7 @@ printf_command (char *arg, int from_tty)
 	    {
 	      /* FIXME: there should be separate int_arg and long_arg.  */
 	      long val = value_as_long (val_args[i]);
-	      printf_filtered (current_substring, val);
+	      printf_filtered_nonliteral (current_substring, val);
 	      break;
 	    }
 	  default:		/* purecov: deadcode */

Attachment: signature.asc
Description: Digital signature


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