diff mbox

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

Message ID 41bc3775-feee-59ec-1463-775e733723fe@gjlay.de
State New
Headers show

Commit Message

Georg-Johann Lay July 27, 2017, 7:58 a.m. UTC
...also backported to v6:

https://gcc.gnu.org/r250573

Johann
lto-plugin/
	Backport from 2017-07-26 gcc-7-branch r250562.
	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-26 gcc-7-branch r250562.
	PR 81487
	* hsa-brig.c (brig_init): Use xasprintf instead of asprintf.
	* tree-ssa-structalias.c (alias_get_name): Same.
diff mbox

Patch

Index: gcc/hsa-brig.c
===================================================================
--- gcc/hsa-brig.c	(revision 250572)
+++ gcc/hsa-brig.c	(working copy)
@@ -492,7 +492,7 @@  brig_init (void)
 	  else
 	    part++;
 	  char *modname2;
-	  asprintf (&modname2, "%s_%s", modname, part);
+	  modname2 = xasprintf ("%s_%s", modname, part);
 	  free (modname);
 	  modname = modname2;
 	}
Index: gcc/tree-ssa-structalias.c
===================================================================
--- gcc/tree-ssa-structalias.c	(revision 250572)
+++ gcc/tree-ssa-structalias.c	(working copy)
@@ -2833,7 +2833,6 @@  alias_get_name (tree decl)
 {
   const char *res = NULL;
   char *temp;
-  int num_printed = 0;
 
   if (!dump_file)
     return "NULL";
@@ -2842,14 +2841,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))
     {
@@ -2860,12 +2856,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: lto-plugin/lto-plugin.c
===================================================================
--- lto-plugin/lto-plugin.c	(revision 250572)
+++ 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
     {