This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
more warning fixes
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org
- Date: Fri, 12 Jan 2007 13:41:49 +1030
- Subject: more warning fixes
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