diff mbox

[v7,committed] Backport PR81487: asprintf -> xasprintf

Message ID 65894fb5-78bb-c38c-4eaa-4d095581c981@gjlay.de
State New
Headers show

Commit Message

Georg-Johann Lay July 26, 2017, 9:07 a.m. UTC
Applied as https://gcc.gnu.org/r250562

Johann

lto-plugin/
	Backport from 2017-07-21 trunk r250428.
	PR lto/81487
	* lto-plugin.c (claim_file_handler): Use xasprintf instead of
	asprintf.
	[hi!=0]: Swap hi and lo arguments supplied to xasprintf.
gcc/
	Backport from 2017-07-25 trunk r250499.
	PR 81487
	* hsa-brig.c (brig_init): Use xasprintf instead of asprintf.
	* gimple-pretty-print.c (dump_probability): Same.
	* tree-ssa-structalias.c (alias_get_name): Same.


On 26.07.2017 09:54, Richard Biener wrote:
> On Tue, Jul 25, 2017 at 10:01 PM, Georg-Johann Lay <avr@gjlay.de> wrote:
>> Richard Biener schrieb:
>>>
>>> On Mon, Jul 24, 2017 at 10:19 AM, Georg-Johann Lay <avr@gjlay.de> wrote:
>>>>
>>>> Hi, as proposed in
>>>>
>>>> https://gcc.gnu.org/ml/gcc-patches/2017-07/msg01294.html
>>>>
>>>> this patch does more asprintf -> xasprintf replacements.
>>>>
>>>> Bootstrapped + reg-tested on x86_64-linux.
>>>>
>>>> Ok for trunk?
>>>
>>> Ok.
>>>
>>> Thanks,
>>> Richard.
>>
>>
>> Is this something we want to backport to v7 ?
> 
> Yes.
> 
> Richard.
diff mbox

Patch

Index: lto-plugin/lto-plugin.c
===================================================================
--- lto-plugin/lto-plugin.c	(revision 250560)
+++ lto-plugin/lto-plugin.c	(working copy)
@@ -975,17 +975,16 @@  claim_file_handler (const struct ld_plug
 
   if (file->offset != 0)
     {
-      char *objname;
       /* We pass the offset of the actual file, not the archive header.
          Can't use PRIx64, because that's C99, so we have to print the
-	 64-bit hex int as two 32-bit ones. */
-      int lo, hi, t;
+	 64-bit hex int as two 32-bit ones.  Use xasprintf instead of
+	 asprintf because asprintf doesn't work as expected on some older
+	 mingw32 hosts.  */
+      int lo, hi;
       lo = file->offset & 0xffffffff;
       hi = ((int64_t)file->offset >> 32) & 0xffffffff;
-      t = hi ? asprintf (&objname, "%s@0x%x%08x", file->name, lo, hi)
-	     : asprintf (&objname, "%s@0x%x", file->name, lo);
-      check (t >= 0, LDPL_FATAL, "asprintf failed");
-      lto_file.name = objname;
+      lto_file.name = hi ? xasprintf ("%s@0x%x%08x", file->name, hi, lo)
+      			 : xasprintf ("%s@0x%x", file->name, lo);
     }
   else
     {
Index: gcc/gimple-pretty-print.c
===================================================================
--- gcc/gimple-pretty-print.c	(revision 250560)
+++ gcc/gimple-pretty-print.c	(working copy)
@@ -89,7 +89,7 @@  dump_probability (int value)
     return "[0.01%]";
 
   char *buf;
-  asprintf (&buf, "[%.2f%%]", fvalue);
+  buf = xasprintf ("[%.2f%%]", fvalue);
   const char *ret = xstrdup_for_dump (buf);
   free (buf);
 
Index: gcc/tree-ssa-structalias.c
===================================================================
--- gcc/tree-ssa-structalias.c	(revision 250560)
+++ gcc/tree-ssa-structalias.c	(working copy)
@@ -2827,7 +2827,6 @@  alias_get_name (tree decl)
 {
   const char *res = NULL;
   char *temp;
-  int num_printed = 0;
 
   if (!dump_file)
     return "NULL";
@@ -2836,14 +2835,11 @@  alias_get_name (tree decl)
     {
       res = get_name (decl);
       if (res)
-	num_printed = asprintf (&temp, "%s_%u", res, SSA_NAME_VERSION (decl));
+	temp = xasprintf ("%s_%u", res, SSA_NAME_VERSION (decl));
       else
-	num_printed = asprintf (&temp, "_%u", SSA_NAME_VERSION (decl));
-      if (num_printed > 0)
-	{
-	  res = ggc_strdup (temp);
-	  free (temp);
-	}
+	temp = xasprintf ("_%u", SSA_NAME_VERSION (decl));
+      res = ggc_strdup (temp);
+      free (temp);
     }
   else if (DECL_P (decl))
     {
@@ -2854,12 +2850,9 @@  alias_get_name (tree decl)
 	  res = get_name (decl);
 	  if (!res)
 	    {
-	      num_printed = asprintf (&temp, "D.%u", DECL_UID (decl));
-	      if (num_printed > 0)
-		{
-		  res = ggc_strdup (temp);
-		  free (temp);
-		}
+	      temp = xasprintf ("D.%u", DECL_UID (decl));
+	      res = ggc_strdup (temp);
+	      free (temp);
 	    }
 	}
     }
Index: gcc/hsa-brig.c
===================================================================
--- gcc/hsa-brig.c	(revision 250560)
+++ gcc/hsa-brig.c	(working copy)
@@ -499,7 +499,7 @@  brig_init (void)
 	  else
 	    part++;
 	  char *modname2;
-	  asprintf (&modname2, "%s_%s", modname, part);
+	  modname2 = xasprintf ("%s_%s", modname, part);
 	  free (modname);
 	  modname = modname2;
 	}