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]

PATCH COMMITTED: PR 6493: Work around -D_FORTIFY_SOURCE


PR 6493 is about a warning in gold when compiling with
-D_FORTIFY_SOURCE (at least, I assume they are using that -D option,
as otherwise the bug report does not make sense).  In this case gold
is calling write in an error case, so it is correctly ignoring the
return value.  This patch adds some pointless uses of the return value
to avoid the warning.

Ian


2008-05-09  Ian Lance Taylor  <iant@google.com>

	PR 6493
	* gold.cc (gold_nomem): Use return value of write.


Index: gold.cc
===================================================================
RCS file: /cvs/src/src/gold/gold.cc,v
retrieving revision 1.55
diff -p -u -r1.55 gold.cc
--- gold.cc	7 May 2008 06:08:01 -0000	1.55
+++ gold.cc	9 May 2008 14:12:14 -0000
@@ -60,9 +60,18 @@ gold_nomem()
   // We are out of memory, so try hard to print a reasonable message.
   // Note that we don't try to translate this message, since the
   // translation process itself will require memory.
-  write(2, program_name, strlen(program_name));
-  const char* const s = ": out of memory\n";
-  write(2, s, strlen(s));
+
+  // LEN only exists to avoid a pointless warning when write is
+  // declared with warn_use_result, as when compiling with
+  // -D_USE_FORTIFY on GNU/Linux.  Casting to void does not appear to
+  // work, at least not with gcc 4.3.0.
+
+  ssize_t len = write(2, program_name, strlen(program_name));
+  if (len >= 0)
+    {
+      const char* const s = ": out of memory\n";
+      len = write(2, s, strlen(s));
+    }
   gold_exit(false);
 }
 

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