* eliminate warnings in printcmd.c
@ 2004-12-10 4:31 Ben Elliston
2004-12-10 7:45 ` Daniel Jacobowitz
0 siblings, 1 reply; 2+ messages in thread
From: Ben Elliston @ 2004-12-10 4:31 UTC (permalink / raw)
To: gdb-patches
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: eliminate warnings in printcmd.c
2004-12-10 4:31 eliminate warnings in printcmd.c Ben Elliston
@ 2004-12-10 7:45 ` Daniel Jacobowitz
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2004-12-10 7:45 UTC (permalink / raw)
To: Ben Elliston; +Cc: gdb-patches
On Fri, Dec 10, 2004 at 03:06:50PM +1100, Ben Elliston wrote:
> 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 :-)
It wouldn't be hard to do. The flow of printf_command is fairly
simple; part of each substring could be replaced by puts, and the rest
by printf with fixed format strings using %*.*. You're welcome to
implement that ;-)
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-12-10 4:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-10 4:31 eliminate warnings in printcmd.c Ben Elliston
2004-12-10 7:45 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox