From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7331 invoked by alias); 12 Jan 2007 03:12:01 -0000 Received: (qmail 7318 invoked by uid 22791); 12 Jan 2007 03:12:00 -0000 X-Spam-Check-By: sourceware.org Received: from omta03ps.mx.bigpond.com (HELO omta03ps.mx.bigpond.com) (144.140.82.155) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 12 Jan 2007 03:11:55 +0000 Received: from oaamta03ps.mx.bigpond.com ([60.226.252.218]) by omta03ps.mx.bigpond.com with ESMTP id <20070112031151.RFWT24030.omta03ps.mx.bigpond.com@oaamta03ps.mx.bigpond.com> for ; Fri, 12 Jan 2007 03:11:51 +0000 Received: from bubble.grove.modra.org ([60.226.252.218]) by oaamta03ps.mx.bigpond.com with ESMTP id <20070112031151.NMUT21928.oaamta03ps.mx.bigpond.com@bubble.grove.modra.org> for ; Fri, 12 Jan 2007 03:11:51 +0000 Received: by bubble.grove.modra.org (Postfix, from userid 500) id EF3932FB05A; Fri, 12 Jan 2007 13:41:49 +1030 (CST) Date: Fri, 12 Jan 2007 03:12:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: more warning fixes Message-ID: <20070112031148.GC16555@bubble.grove.modra.org> Mail-Followup-To: binutils@sourceware.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2007-01/txt/msg00152.txt.bz2 Warning fixes, and remove a bogus check for "negative" file sizes. Really big files are becoming more common these days. binutils/ * 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. gas/ * input-file.c (input_file_open): Check fgets return. Index: binutils/ar.c =================================================================== RCS file: /cvs/src/src/binutils/ar.c,v retrieving revision 1.47 diff -u -p -r1.47 ar.c --- binutils/ar.c 13 Oct 2006 09:43:28 -0000 1.47 +++ binutils/ar.c 12 Jan 2007 02:41:17 -0000 @@ -777,10 +777,10 @@ open_inarch (const char *archive_filenam static void print_contents (bfd *abfd) { - int ncopied = 0; + size_t ncopied = 0; char *cbuf = xmalloc (BUFSIZE); struct stat buf; - long size; + size_t size; if (bfd_stat_arch_elt (abfd, &buf) != 0) /* xgettext:c-format */ fatal (_("internal stat error on %s"), bfd_get_filename (abfd)); @@ -795,8 +795,8 @@ print_contents (bfd *abfd) while (ncopied < size) { - int nread; - int tocopy = size - ncopied; + size_t nread; + size_t tocopy = size - ncopied; if (tocopy > BUFSIZE) tocopy = BUFSIZE; @@ -805,7 +805,8 @@ print_contents (bfd *abfd) /* xgettext:c-format */ fatal (_("%s is not a valid archive"), bfd_get_filename (bfd_my_archive (abfd))); - fwrite (cbuf, 1, nread, stdout); + if (fwrite (cbuf, 1, nread, stdout) != nread) + fatal ("stdout: %s", strerror (errno)); ncopied += tocopy; } free (cbuf); @@ -826,9 +827,9 @@ extract_file (bfd *abfd) { FILE *ostream; char *cbuf = xmalloc (BUFSIZE); - int nread, tocopy; - long ncopied = 0; - long size; + size_t nread, tocopy; + size_t ncopied = 0; + size_t size; struct stat buf; if (bfd_stat_arch_elt (abfd, &buf) != 0) @@ -836,10 +837,6 @@ extract_file (bfd *abfd) fatal (_("internal stat error on %s"), bfd_get_filename (abfd)); size = buf.st_size; - if (size < 0) - /* xgettext:c-format */ - fatal (_("stat returns negative size for %s"), bfd_get_filename (abfd)); - if (verbose) printf ("x - %s\n", bfd_get_filename (abfd)); @@ -888,7 +885,8 @@ extract_file (bfd *abfd) output_file = ostream; } - fwrite (cbuf, 1, nread, ostream); + if (fwrite (cbuf, 1, nread, ostream) != nread) + fatal ("%s: %s", output_filename, strerror (errno)); ncopied += tocopy; } Index: binutils/readelf.c =================================================================== RCS file: /cvs/src/src/binutils/readelf.c,v retrieving revision 1.356 diff -u -p -r1.356 readelf.c --- binutils/readelf.c 8 Jan 2007 18:42:36 -0000 1.356 +++ binutils/readelf.c 12 Jan 2007 02:41:23 -0000 @@ -3520,7 +3520,8 @@ process_program_headers (FILE *file) error (_("Internal error: failed to create format string to display program interpreter")); program_interpreter[0] = 0; - fscanf (file, fmt, program_interpreter); + if (fscanf (file, fmt, program_interpreter) <= 0) + error (_("Unable to read program interpreter name\n")); if (do_segments) printf (_("\n [Requesting program interpreter: %s]"), Index: gas/input-file.c =================================================================== RCS file: /cvs/src/src/gas/input-file.c,v retrieving revision 1.23 diff -u -p -r1.23 input-file.c --- gas/input-file.c 13 Sep 2006 10:15:59 -0000 1.23 +++ gas/input-file.c 12 Jan 2007 02:41:25 -0000 @@ -163,8 +163,8 @@ input_file_open (char *filename, /* "" m c = getc (f_in); if (c == 'N') { - fgets (buf, 80, f_in); - if (!strncmp (buf, "O_APP", 5) && ISSPACE (buf[5])) + if (fgets (buf, sizeof (buf), f_in) + && !strncmp (buf, "O_APP", 5) && ISSPACE (buf[5])) preprocess = 0; if (!strchr (buf, '\n')) ungetc ('#', f_in); /* It was longer. */ @@ -173,8 +173,8 @@ input_file_open (char *filename, /* "" m } else if (c == 'A') { - fgets (buf, 80, f_in); - if (!strncmp (buf, "PP", 2) && ISSPACE (buf[2])) + if (fgets (buf, sizeof (buf), f_in) + && !strncmp (buf, "PP", 2) && ISSPACE (buf[2])) preprocess = 1; if (!strchr (buf, '\n')) ungetc ('#', f_in); -- Alan Modra IBM OzLabs - Linux Technology Centre