Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ben Elliston" <bje@au1.ibm.com>
To: gdb-patches@sources.redhat.com
Subject: eliminate warnings in printcmd.c
Date: Fri, 10 Dec 2004 04:31:00 -0000	[thread overview]
Message-ID: <20041210040650.GB30314@namadgi> (raw)

[-- Attachment #1: Type: text/plain, Size: 3236 bytes --]

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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2004-12-10  4:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-10  4:31 Ben Elliston [this message]
2004-12-10  7:45 ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041210040650.GB30314@namadgi \
    --to=bje@au1.ibm.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox