This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Re: work around daft warning


On Fri, May 18, 2012 at 11:19:06AM +0000, John Tytgat wrote:
> When asprintf() fails, contents of label is undefined, isn't it better

What I should have done was replaced asprintf as follows.  Now xmalloc
will report the out-of-memory failure and exit gas.

	* config/tc-dlx.c (s_proc): Don't use asprintf.

Index: gas/config/tc-dlx.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-dlx.c,v
retrieving revision 1.26
diff -u -p -r1.26 tc-dlx.c
--- gas/config/tc-dlx.c	18 May 2012 05:48:50 -0000	1.26
+++ gas/config/tc-dlx.c	18 May 2012 23:17:23 -0000
@@ -246,8 +246,10 @@ s_proc (int end_p)
 	     char prepended.  */
 	  if (leading_char)
 	    {
-	      if (asprintf (&label, "%c%s", leading_char, name))
-		{ /* Avoid warning */ }
+	      unsigned len = strlen (name) + 1;
+	      label = xmalloc (len + 1);
+	      label[0] = leading_char;
+	      memcpy (label + 1, name, len);
 	    }
 	  else
 	    label = name;

-- 
Alan Modra
Australia Development Lab, IBM


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