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] binutils/ar.c: Fix a build failure on mingw32.


Hi,

Attached is a patch to fix a build failure on mingw32.

Alan's patch on 2007-01-12

2007-01-12  Alan Modra  <amodra@bigpond.net.au>

	* ar.c (open_inarch): Check fwrite return.  Use size_t.
	(extract_file): Likewise.  Remove test for "negative" file size.
	* readelf.c (process_program_headers): Check fscanf return.

introduced a construct like so:

  if ((size_t) fwrite (cbuf, 1, nread, ostream) != nread)

It turns out that this triggers a build failure on mingw32 because
fwrite may return int instead of size_t on a certain configuration of
mingw32.

This patch works around the problem by casting the return value to
size_t.

Tested by building binutils.  OK to apply?

Kazu Hirata

2007-01-23  Kazu Hirata  <kazu@codesourcery.com>

	* ar.c (print_contents, extract_file): Cast the return value
	of fwrite to size_t.

Index: binutils/ar.c
===================================================================
RCS file: /cvs/src/src/binutils/ar.c,v
retrieving revision 1.48
diff -u -d -p -r1.48 ar.c
--- binutils/ar.c	12 Jan 2007 03:12:56 -0000	1.48
+++ binutils/ar.c	23 Jan 2007 17:28:14 -0000
@@ -805,7 +805,11 @@ print_contents (bfd *abfd)
 	/* xgettext:c-format */
 	fatal (_("%s is not a valid archive"),
 	       bfd_get_filename (bfd_my_archive (abfd)));
-      if (fwrite (cbuf, 1, nread, stdout) != nread)
+
+      /* fwrite in mingw32 may return int instead of size_t. Cast the
+	 return value to size_t to avoid comparison between signed and
+	 unsigned values.  */
+      if ((size_t) fwrite (cbuf, 1, nread, stdout) != nread)
 	fatal ("stdout: %s", strerror (errno));
       ncopied += tocopy;
     }
@@ -885,7 +889,11 @@ extract_file (bfd *abfd)
 
 	    output_file = ostream;
 	  }
-	if (fwrite (cbuf, 1, nread, ostream) != nread)
+
+	/* fwrite in mingw32 may return int instead of size_t. Cast
+	   the return value to size_t to avoid comparison between
+	   signed and unsigned values.  */
+	if ((size_t) fwrite (cbuf, 1, nread, ostream) != nread)
 	  fatal ("%s: %s", output_filename, strerror (errno));
 	ncopied += tocopy;
       }


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