This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] libiberty/make-relative-prefix.c, save_string, use xmalloc over malloc
- From: Michael Snyder <msnyder at vmware dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "dj at redhat dot com" <dj at redhat dot com>
- Date: Sun, 06 Mar 2011 15:29:45 -0800
- Subject: [RFA] libiberty/make-relative-prefix.c, save_string, use xmalloc over malloc
I know the callers of save_string check its return value for null, but
by then it's too late -- we've memcpy'd over a null pointer.
OK?
2011-03-06 Michael Snyder <msnyder@msnyder-server.eng.vmware.com>
* make-relative-prefix.c (save_string): Use xmalloc over malloc.
Index: make-relative-prefix.c
===================================================================
RCS file: /cvs/src/src/libiberty/make-relative-prefix.c,v
retrieving revision 1.13
diff -u -p -r1.13 make-relative-prefix.c
--- make-relative-prefix.c 3 Feb 2011 07:23:59 -0000 1.13
+++ make-relative-prefix.c 6 Mar 2011 23:25:35 -0000
@@ -103,7 +103,7 @@ static void free_split_directories (char
static char *
save_string (const char *s, int len)
{
- char *result = (char *) malloc (len + 1);
+ char *result = (char *) xmalloc (len + 1);
memcpy (result, s, len);
result[len] = 0;