This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]