This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[commit] Eliminate sprintf from infcall.c
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 10 Aug 2003 13:20:58 -0400
- Subject: [commit] Eliminate sprintf from infcall.c
Hello,
This gets rid of a -Wformat-nonliteral warning (and eliminates an
sprintf call). It's a little shaky since it couldn't do a more normal
make_cleanup(xfree) - code below would discard the cleanup :-(
committed,
Andrew
2003-08-10 Andrew Cagney <cagney@redhat.com>
* infcall.c (call_function_by_hand): Use xstrprintf instead of
sprintf. Make "name" constant.
Index: infcall.c
===================================================================
RCS file: /cvs/src/src/gdb/infcall.c,v
retrieving revision 1.21
diff -u -r1.21 infcall.c
--- infcall.c 7 Aug 2003 23:41:57 -0000 1.21
+++ infcall.c 10 Aug 2003 17:16:21 -0000
@@ -937,7 +937,7 @@
if (stopped_by_random_signal || !stop_stack_dummy)
{
/* Find the name of the function we're about to complain about. */
- char *name = NULL;
+ const char *name = NULL;
{
struct symbol *symbol = find_pc_function (funaddr);
if (symbol)
@@ -949,17 +949,17 @@
if (msymbol)
name = SYMBOL_PRINT_NAME (msymbol);
}
+ if (name == NULL)
+ {
+ /* Can't use a cleanup here. It is discarded, instead use
+ an alloca. */
+ char *tmp = xstrprintf ("at %s", local_hex_string (funaddr));
+ char *a = alloca (strlen (tmp) + 1);
+ strcpy (a, tmp);
+ xfree (tmp);
+ name = a;
+ }
}
- if (name == NULL)
- {
- /* NOTE: cagney/2003-04-23: Don't blame me. This code dates
- back to 1993-07-08, I simply moved it. */
- char format[80];
- sprintf (format, "at %s", local_hex_format ());
- name = alloca (80);
- /* FIXME-32x64: assumes funaddr fits in a long. */
- sprintf (name, format, (unsigned long) funaddr);
- }
if (stopped_by_random_signal)
{
/* We stopped inside the FUNCTION because of a random