This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

PATCH: silence unused result warnings


Further to my recent libiberty change, this patch silences unused result
warnings from C library functions that are marked accordingly in system
headers (notably some GNU/Linux distributions).  Tested with a bootstrap
on x86_64-linux-gnu.

Okay for mainline?

Ben


2009-11-23  Ben Elliston  <bje@au.ibm.com>

	* diagnostic.c (build_message_string): Check asprintf, vasprintf
	return values.
	* final.c (output_operand_lossage): Likewise.
	* toplev.c (pch_option_mismatch): Likewise.
	* tree-ssa-structalias.c (create_function_info_for): Likewise.
	(create_variable_info_for): Likewise.
	* tree-data-ref.c (dot_rdg): Check system(3) return value.

lto/
	* lto.c (lto_resolution_read): Check fscanf and fread results.

Index: diagnostic.c
===================================================================
--- diagnostic.c	(revision 154431)
+++ diagnostic.c	(working copy)
@@ -68,7 +68,8 @@ build_message_string (const char *msg, .
   va_list ap;
 
   va_start (ap, msg);
-  vasprintf (&str, msg, ap);
+  if (vasprintf (&str, msg, ap) < 0)
+    gcc_unreachable ();
   va_end (ap);
 
   return str;
Index: final.c
===================================================================
--- final.c	(revision 154431)
+++ final.c	(working copy)
@@ -3079,8 +3079,10 @@ output_operand_lossage (const char *cmsg
   va_start (ap, cmsgid);
 
   pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
-  asprintf (&fmt_string, "%s%s", pfx_str, _(cmsgid));
-  vasprintf (&new_message, fmt_string, ap);
+  if (asprintf (&fmt_string, "%s%s", pfx_str, _(cmsgid)) < 0)
+    gcc_unreachable ();
+  if (vasprintf (&new_message, fmt_string, ap) < 0)
+    gcc_unreachable ();
 
   if (this_is_asm_operands)
     error_for_asm (this_is_asm_operands, "%s", new_message);
Index: toplev.c
===================================================================
--- toplev.c	(revision 154431)
+++ toplev.c	(working copy)
@@ -1546,10 +1546,12 @@ pch_option_mismatch (const char *option)
 {
   char *r;
 
-  asprintf (&r, _("created and used with differing settings of '%s'"), option);
-  if (r == NULL)
+  if (asprintf (&r,
+		_("created and used with differing settings of '%s'"),
+		option) < 0)
     return _("out of memory");
-  return r;
+  else
+    return r;
 }
 
 /* Default version of pch_valid_p.  */
Index: tree-data-ref.c
===================================================================
--- tree-data-ref.c	(revision 154431)
+++ tree-data-ref.c	(working copy)
@@ -4690,7 +4690,8 @@ dot_rdg (struct graph *rdg)
   dot_rdg_1 (file, rdg);
   fclose (file);
 
-  system ("dotty /tmp/rdg.dot");
+  if (system ("dotty /tmp/rdg.dot") < 0)
+    gcc_unreachable ();
 }
 
 
Index: tree-ssa-structalias.c
===================================================================
--- tree-ssa-structalias.c	(revision 154431)
+++ tree-ssa-structalias.c	(working copy)
@@ -4354,7 +4354,8 @@ create_function_info_for (tree decl, con
       if (arg)
 	argdecl = arg;
 
-      asprintf (&tempname, "%s.arg%d", name, i-1);
+      if (asprintf (&tempname, "%s.arg%d", name, i-1) < 0)
+	gcc_unreachable ();
       newname = ggc_strdup (tempname);
       free (tempname);
 
@@ -4386,7 +4387,8 @@ create_function_info_for (tree decl, con
       if (DECL_RESULT (decl))
 	resultdecl = DECL_RESULT (decl);
 
-      asprintf (&tempname, "%s.result", name);
+      if (asprintf (&tempname, "%s.result", name) < 0)
+	gcc_unreachable ();
       newname = ggc_strdup (tempname);
       free (tempname);
 
@@ -4538,9 +4540,10 @@ create_variable_info_for (tree decl, con
 
 	  if (dump_file)
 	    {
-	      asprintf (&tempname, "%s." HOST_WIDE_INT_PRINT_DEC
-			"+" HOST_WIDE_INT_PRINT_DEC,
-			vi->name, fo->offset, fo->size);
+	      if (asprintf (&tempname, "%s." HOST_WIDE_INT_PRINT_DEC
+			    "+" HOST_WIDE_INT_PRINT_DEC,
+			    vi->name, fo->offset, fo->size) < 0)
+		gcc_unreachable ();
 	      newname = ggc_strdup (tempname);
 	      free (tempname);
 	    }
Index: lto/lto.c
===================================================================
--- lto/lto.c	(revision 154431)
+++ lto/lto.c	(working copy)
@@ -292,9 +292,15 @@ lto_resolution_read (FILE *resolution, l
 
   name_len = strlen (file->filename);
   obj_name = XNEWVEC (char, name_len + 1);
-  fscanf (resolution, " ");   /* Read white space. */
 
-  fread (obj_name, sizeof (char), name_len, resolution);
+  /* Read white space.  */
+  if (fscanf (resolution, " ") < 0)
+    internal_error ("unexpected EOF in resolution file.");
+
+  if (fread (obj_name, sizeof (char), name_len, resolution) < name_len
+      && feof (resolution))
+    internal_error ("unexpected EOF in resolution file.");
+
   obj_name[name_len] = '\0';
   if (strcmp (obj_name, file->filename) != 0)
     internal_error ("unexpected file name %s in linker resolution file. "
@@ -314,7 +320,8 @@ lto_resolution_read (FILE *resolution, l
 
   free (obj_name);
 
-  fscanf (resolution, "%u", &num_symbols);
+  if (fscanf (resolution, "%u", &num_symbols) < 0)
+    internal_error ("unexpected EOF in the resolution file.");
 
   for (i = 0; i < num_symbols; i++)
     {



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