This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[COMMIT] Use xasprintf instead of sprintf in cp-abi.c
- From: Mark Kettenis <kettenis at gnu dot org>
- To: gdb-patches at sourceware dot org
- Date: Sun, 13 Mar 2005 21:11:22 +0100 (CET)
- Subject: [COMMIT] Use xasprintf instead of sprintf in cp-abi.c
sprintf() is dangerous and should not be used! Committed as obvious.
Mark
P.S. Andrew, any chance to get this added to the ARI?
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* cp-abi.c (set_cp_abi_as_auto_default): Use xasprintf instead of
a combination of xmalloc and sprintf.
Index: cp-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-abi.c,v
retrieving revision 1.11
diff -u -p -r1.11 cp-abi.c
--- cp-abi.c 14 Feb 2005 18:10:07 -0000 1.11
+++ cp-abi.c 13 Mar 2005 19:43:07 -0000
@@ -145,14 +145,11 @@ set_cp_abi_as_auto_default (const char *
auto_cp_abi = *abi;
auto_cp_abi.shortname = "auto";
- new_longname = xmalloc (strlen ("currently ") + 1 + strlen (abi->shortname)
- + 1 + 1);
- sprintf (new_longname, "currently \"%s\"", abi->shortname);
+ xasprintf (&new_longname, "currently \"%s\"", abi->shortname);
auto_cp_abi.longname = new_longname;
- new_doc = xmalloc (strlen ("Automatically selected; currently ")
- + 1 + strlen (abi->shortname) + 1 + 1);
- sprintf (new_doc, "Automatically selected; currently \"%s\"", abi->shortname);
+ xasprintf (&new_doc, "Automatically selected; currently \"%s\"",
+ abi->shortname);
auto_cp_abi.doc = new_doc;
/* Since we copy the current ABI into current_cp_abi instead of