This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa] some -Wformat-nonliteral changes
- From: David Carlton <carlton at kealia dot com>
- To: gdb-patches at sources dot redhat dot com
- Cc: Andrew at kealia dot com, Cagney at kealia dot com
- Date: Fri, 01 Aug 2003 13:30:55 -0700
- Subject: [rfa] some -Wformat-nonliteral changes
As promised, here are the easy -Wformat-nonliteral changes. Most of
them consist of replacing calls like fprintf(stream, foo) with
fputs(foo, stream). A few of them consist of replacing error(msg)
with error("%s",msg). And one of them is an actual bug fix - there's
a call to internal_error that left out __FILE__ and __LINE__.
Having said that, there's still a lot of warnings triggered by
-Wformat-nonliteral; some of them are in situations with a fairly easy
workaround, but some of them are a little more delicate. I would
definitely recommend that the -Wformat-nonliteral patch be reverted
for the time being, because it's breaking compiles for some of us.
I've tested this with GCC 3.2, i686-pc-linux-gnu, DWARF-2; no new
regressions. It also doesn't turn up any regressions on GDB 6.0; I'd
lean towards applying the internal_error bug fix part of it to the
branch, but I don't have much of an opinion one way or another about
applying the entire patch.
OK to apply? It should all be obvious, but I might as well have
another set of eyes proofreading it.
David Carlton
carlton@kealia.com
2003-08-01 David Carlton <carlton@kealia.com>
* charset.c (cached_iconv_convert): Add __FILE__ and __LINE__ args
to internal_error call.
* source.c (forward_search_command): Add "%s" format argument.
(reverse_search_command): Ditto.
* top.c (quit_confirm): Ditto.
* cli/cli-setshow.c (do_setshow_command): Ditto.
* cp-valprint.c (cp_print_class_method): Replace
{f,}printf_{un,}filtered by {f,}puts_{un,}filtered.
(cp_print_class_member): Ditto.
* event-top.c (command_line_handler): Ditto.
* linux-proc.c (linux_info_proc_cmd): Ditto.
* p-typeprint.c (pascal_type_print_base): Ditto.
* p-valprint.c (pascal_object_print_class_method): Ditto.
(pascal_object_print_class_member): Ditto.
* printcmd.c (print_scalar_formatted,printf_command): Ditto.
* remote.c (remote_cisco_section_offsets): Ditto.
* top.c (command_line_input): Ditto.
* utils.c (vwarning,error_stream,quit): Ditto.
* valprint.c (print_floating,print_binary_chars)
(print_octal_chars,print_decimal_chars,print_hex_chars): Ditto.
2003-08-01 David Carlton <carlton@kealia.com>
* mi-main.c (mi_error_last_message): Add "%s" second argument to
xasprintf call.
2003-08-01 David Carlton <carlton@kealia.com>
* generic/gdbtk.c (gdbtk_source_start_file): Add "%s" first
argument to error call.
(tk_command): Ditto.
(view_command): Ditto.
Index: charset.c
===================================================================
RCS file: /cvs/src/src/gdb/charset.c,v
retrieving revision 1.5
diff -u -p -r1.5 charset.c
--- charset.c 8 Jun 2003 18:27:12 -0000 1.5
+++ charset.c 1 Aug 2003 20:02:28 -0000
@@ -443,7 +443,8 @@ cached_iconv_convert (struct cached_icon
return 0;
/* Anything else is mysterious. */
- internal_error ("Error converting character `%d' from `%s' to `%s' "
+ internal_error (__FILE__, __LINE__,
+ "Error converting character `%d' from `%s' to `%s' "
"character set: %s",
from_char, ci->from->name, ci->to->name,
safe_strerror (errno));
Index: cp-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-valprint.c,v
retrieving revision 1.22
diff -u -p -r1.22 cp-valprint.c
--- cp-valprint.c 21 Jun 2003 23:27:53 -0000 1.22
+++ cp-valprint.c 1 Aug 2003 20:02:28 -0000
@@ -143,7 +143,7 @@ cp_print_class_method (char *valaddr,
char *demangled_name;
fprintf_filtered (stream, "&");
- fprintf_filtered (stream, kind);
+ fputs_filtered (kind, stream);
demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j),
DMGL_ANSI | DMGL_PARAMS);
if (demangled_name == NULL)
@@ -720,7 +720,7 @@ cp_print_class_member (char *valaddr, st
if (i < len)
{
char *name;
- fprintf_filtered (stream, prefix);
+ fputs_filtered (prefix, stream);
name = type_name_no_tag (domain);
if (name)
fputs_filtered (name, stream);
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.27
diff -u -p -r1.27 event-top.c
--- event-top.c 2 Jun 2003 16:02:58 -0000 1.27
+++ event-top.c 1 Aug 2003 20:02:28 -0000
@@ -612,7 +612,7 @@ command_line_handler (char *rl)
if (annotation_level > 1 && instream == stdin)
{
printf_unfiltered ("\n\032\032post-");
- printf_unfiltered (async_annotation_suffix);
+ puts_unfiltered (async_annotation_suffix);
printf_unfiltered ("\n");
}
Index: linux-proc.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-proc.c,v
retrieving revision 1.15
diff -u -p -r1.15 linux-proc.c
--- linux-proc.c 19 Jun 2003 22:52:03 -0000 1.15
+++ linux-proc.c 1 Aug 2003 20:02:28 -0000
@@ -446,7 +446,7 @@ linux_info_proc_cmd (char *args, int fro
if ((procfile = fopen (fname1, "r")) > 0)
{
while (fgets (buffer, sizeof (buffer), procfile) != NULL)
- printf_filtered (buffer);
+ puts_filtered (buffer);
fclose (procfile);
}
else
Index: p-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-typeprint.c,v
retrieving revision 1.10
diff -u -p -r1.10 p-typeprint.c
--- p-typeprint.c 29 Jul 2002 22:55:26 -0000 1.10
+++ p-typeprint.c 1 Aug 2003 20:02:28 -0000
@@ -460,8 +460,8 @@ pascal_type_print_base (struct type *typ
/* void pointer */
if ((TYPE_CODE (type) == TYPE_CODE_PTR) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID))
{
- fprintf_filtered (stream,
- TYPE_NAME (type) ? TYPE_NAME (type) : "pointer");
+ fputs_filtered (TYPE_NAME (type) ? TYPE_NAME (type) : "pointer",
+ stream);
return;
}
/* When SHOW is zero or less, and there is a valid type name, then always
Index: p-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-valprint.c,v
retrieving revision 1.21
diff -u -p -r1.21 p-valprint.c
--- p-valprint.c 8 Jun 2003 18:27:14 -0000 1.21
+++ p-valprint.c 1 Aug 2003 20:02:28 -0000
@@ -661,7 +661,7 @@ common:
char *demangled_name;
fprintf_filtered (stream, "&");
- fprintf_filtered (stream, kind);
+ fputs_filtered (kind, stream);
demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j),
DMGL_ANSI | DMGL_PARAMS);
if (demangled_name == NULL)
@@ -1080,7 +1080,7 @@ pascal_object_print_class_member (char *
if (i < len)
{
char *name;
- fprintf_filtered (stream, prefix);
+ fputs_filtered (prefix, stream);
name = type_name_no_tag (domain);
if (name)
fputs_filtered (name, stream);
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.64
diff -u -p -r1.64 printcmd.c
--- printcmd.c 22 Jul 2003 15:41:59 -0000 1.64
+++ printcmd.c 1 Aug 2003 20:02:28 -0000
@@ -507,7 +507,7 @@ print_scalar_formatted (void *valaddr, s
strcpy (buf, local_binary_format_prefix ());
strcat (buf, cp);
strcat (buf, local_binary_format_suffix ());
- fprintf_filtered (stream, buf);
+ fputs_filtered (buf, stream);
}
break;
@@ -2003,7 +2003,7 @@ printf_command (char *arg, int from_tty)
current_substring += strlen (current_substring) + 1;
}
/* Print the portion of the format string after the last argument. */
- printf_filtered (last_arg);
+ puts_filtered (last_arg);
}
do_cleanups (old_cleanups);
}
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.110
diff -u -p -r1.110 remote.c
--- remote.c 30 Jun 2003 15:50:52 -0000 1.110
+++ remote.c 1 Aug 2003 20:02:30 -0000
@@ -2071,7 +2071,7 @@ remote_cisco_section_offsets (bfd_vma te
sprintf_vma (tmp + strlen (tmp), data_addr);
sprintf (tmp + strlen (tmp), " bss = 0x");
sprintf_vma (tmp + strlen (tmp), bss_addr);
- fprintf_filtered (gdb_stdlog, tmp);
+ fputs_filtered (tmp, gdb_stdlog);
fprintf_filtered (gdb_stdlog,
"Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
paddr_nz (*text_offs),
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.42
diff -u -p -r1.42 source.c
--- source.c 14 May 2003 17:43:18 -0000 1.42
+++ source.c 1 Aug 2003 20:02:30 -0000
@@ -1361,7 +1361,7 @@ forward_search_command (char *regex, int
msg = (char *) re_comp (regex);
if (msg)
- error (msg);
+ error ("%s", msg);
if (current_source_symtab == 0)
select_source_symtab (0);
@@ -1457,7 +1457,7 @@ reverse_search_command (char *regex, int
msg = (char *) re_comp (regex);
if (msg)
- error (msg);
+ error ("%s", msg);
if (current_source_symtab == 0)
select_source_symtab (0);
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.73
diff -u -p -r1.73 top.c
--- top.c 8 Jun 2003 18:27:14 -0000 1.73
+++ top.c 1 Aug 2003 20:02:30 -0000
@@ -1201,9 +1201,9 @@ command_line_input (char *prompt_arg, in
if (annotation_level > 1 && instream == stdin)
{
- printf_unfiltered ("\n\032\032pre-");
- printf_unfiltered (annotation_suffix);
- printf_unfiltered ("\n");
+ puts_unfiltered ("\n\032\032pre-");
+ puts_unfiltered (annotation_suffix);
+ puts_unfiltered ("\n");
}
/* Don't use fancy stuff if not talking to stdin. */
@@ -1222,9 +1222,9 @@ command_line_input (char *prompt_arg, in
if (annotation_level > 1 && instream == stdin)
{
- printf_unfiltered ("\n\032\032post-");
- printf_unfiltered (annotation_suffix);
- printf_unfiltered ("\n");
+ puts_unfiltered ("\n\032\032post-");
+ puts_unfiltered (annotation_suffix);
+ puts_unfiltered ("\n");
}
if (!rl || rl == (char *) EOF)
@@ -1686,7 +1686,7 @@ quit_confirm (void)
else
s = "The program is running. Exit anyway? ";
- if (!query (s))
+ if (!query ("%s", s))
return 0;
}
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.103
diff -u -p -r1.103 utils.c
--- utils.c 30 Jun 2003 21:40:05 -0000 1.103
+++ utils.c 1 Aug 2003 20:02:30 -0000
@@ -578,7 +578,7 @@ vwarning (const char *string, va_list ar
wrap_here (""); /* Force out any buffered output */
gdb_flush (gdb_stdout);
if (warning_pre_print)
- fprintf_unfiltered (gdb_stderr, warning_pre_print);
+ fputs_unfiltered (warning_pre_print, gdb_stderr);
vfprintf_unfiltered (gdb_stderr, string, args);
fprintf_unfiltered (gdb_stderr, "\n");
va_end (args);
@@ -644,7 +644,7 @@ error_stream (struct ui_file *stream)
gdb_flush (gdb_stdout);
annotate_error_begin ();
if (error_pre_print)
- fprintf_filtered (gdb_stderr, error_pre_print);
+ fputs_filtered (error_pre_print, gdb_stderr);
ui_file_put (stream, do_write, gdb_stderr);
fprintf_filtered (gdb_stderr, "\n");
@@ -922,7 +922,7 @@ quit (void)
/* Don't use *_filtered; we don't want to prompt the user to continue. */
if (quit_pre_print)
- fprintf_unfiltered (gdb_stderr, quit_pre_print);
+ fputs_unfiltered (quit_pre_print, gdb_stderr);
#ifdef __MSDOS__
/* No steenking SIGINT will ever be coming our way when the
Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.29
diff -u -p -r1.29 valprint.c
--- valprint.c 6 Apr 2003 14:50:15 -0000 1.29
+++ valprint.c 1 Aug 2003 20:02:31 -0000
@@ -452,9 +452,9 @@ print_floating (char *valaddr, struct ty
if (floatformat_is_negative (fmt, valaddr))
fprintf_filtered (stream, "-");
fprintf_filtered (stream, "nan(");
- fprintf_filtered (stream, local_hex_format_prefix ());
- fprintf_filtered (stream, floatformat_mantissa (fmt, valaddr));
- fprintf_filtered (stream, local_hex_format_suffix ());
+ fputs_filtered (local_hex_format_prefix (), stream);
+ fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
+ fputs_filtered (local_hex_format_suffix (), stream);
fprintf_filtered (stream, ")");
return;
}
@@ -515,7 +515,7 @@ print_binary_chars (struct ui_file *stre
/* FIXME: We should be not printing leading zeroes in most cases. */
- fprintf_filtered (stream, local_binary_format_prefix ());
+ fputs_filtered (local_binary_format_prefix (), stream);
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = valaddr;
@@ -553,7 +553,7 @@ print_binary_chars (struct ui_file *stre
}
}
}
- fprintf_filtered (stream, local_binary_format_suffix ());
+ fputs_filtered (local_binary_format_suffix (), stream);
}
/* VALADDR points to an integer of LEN bytes.
@@ -602,7 +602,7 @@ print_octal_chars (struct ui_file *strea
cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
carry = 0;
- fprintf_filtered (stream, local_octal_format_prefix ());
+ fputs_filtered (local_octal_format_prefix (), stream);
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = valaddr;
@@ -701,7 +701,7 @@ print_octal_chars (struct ui_file *strea
}
}
- fprintf_filtered (stream, local_octal_format_suffix ());
+ fputs_filtered (local_octal_format_suffix (), stream);
}
/* VALADDR points to an integer of LEN bytes.
@@ -744,7 +744,7 @@ print_decimal_chars (struct ui_file *str
digits[i] = 0;
}
- fprintf_filtered (stream, local_decimal_format_prefix ());
+ fputs_filtered (local_decimal_format_prefix (), stream);
/* Ok, we have an unknown number of bytes of data to be printed in
* decimal.
@@ -841,7 +841,7 @@ print_decimal_chars (struct ui_file *str
}
xfree (digits);
- fprintf_filtered (stream, local_decimal_format_suffix ());
+ fputs_filtered (local_decimal_format_suffix (), stream);
}
/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
@@ -853,7 +853,7 @@ print_hex_chars (struct ui_file *stream,
/* FIXME: We should be not printing leading zeroes in most cases. */
- fprintf_filtered (stream, local_hex_format_prefix ());
+ fputs_filtered (local_hex_format_prefix (), stream);
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = valaddr;
@@ -872,7 +872,7 @@ print_hex_chars (struct ui_file *stream,
fprintf_filtered (stream, "%02x", *p);
}
}
- fprintf_filtered (stream, local_hex_format_suffix ());
+ fputs_filtered (local_hex_format_suffix (), stream);
}
/* Called by various <lang>_val_print routines to print elements of an
Index: cli/cli-setshow.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-setshow.c,v
retrieving revision 1.12
diff -u -p -r1.12 cli-setshow.c
--- cli/cli-setshow.c 3 Feb 2003 01:18:37 -0000 1.12
+++ cli/cli-setshow.c 1 Aug 2003 20:02:32 -0000
@@ -213,7 +213,7 @@ do_setshow_command (char *arg, int from_
strcat (msg, c->enums[i]);
}
strcat (msg, ".");
- error (msg);
+ error ("%s", msg);
}
p = strchr (arg, ' ');
Index: gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.36
diff -u -p -r1.36 gdbtk.c
--- gdbtk/generic/gdbtk.c 18 Feb 2003 23:33:05 -0000 1.36
+++ gdbtk/generic/gdbtk.c 1 Aug 2003 20:02:33 -0000
@@ -636,7 +636,7 @@ gdbtk_find_main";
#else
/* FIXME: cagney/2002-04-17: Wonder what the lifetime of
``msg'' is - does it need a cleanup? */
- error (msg);
+ error ("%s", msg);
#endif
}
@@ -731,7 +731,7 @@ tk_command (char *cmd, int from_tty)
old_chain = make_cleanup (free, result);
if (retval != TCL_OK)
- error (result);
+ error ("%s", result);
printf_unfiltered ("%s\n", result);
@@ -753,7 +753,7 @@ view_command (char *args, int from_tty)
if (Tcl_Eval (gdbtk_interp, script) != TCL_OK)
{
Tcl_Obj *obj = Tcl_GetObjResult (gdbtk_interp);
- error (Tcl_GetStringFromObj (obj, NULL));
+ error ("%s", Tcl_GetStringFromObj (obj, NULL));
}
do_cleanups (old_chain);
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.48
diff -u -p -r1.48 mi-main.c
--- mi/mi-main.c 11 Jun 2003 19:38:27 -0000 1.48
+++ mi/mi-main.c 1 Aug 2003 20:02:34 -0000
@@ -101,7 +101,7 @@ void
mi_error_last_message (void)
{
char *s = error_last_message ();
- xasprintf (&mi_error_message, s);
+ xasprintf (&mi_error_message, "%s", s);
xfree (s);
}