diff options
author | Alan Modra <amodra@gmail.com> | 2007-01-12 03:12:56 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2007-01-12 03:12:56 +0000 |
commit | 7bd7b3eff2840d8309852c8a4091cb3b589fccd8 (patch) | |
tree | b46abc70cdcb900c0dc2719375d2054ec5301f6c /binutils | |
parent | 0bbe7a79f595b156a9a9ab3042f44d7218b933e0 (diff) | |
download | gdb-7bd7b3eff2840d8309852c8a4091cb3b589fccd8.zip gdb-7bd7b3eff2840d8309852c8a4091cb3b589fccd8.tar.gz gdb-7bd7b3eff2840d8309852c8a4091cb3b589fccd8.tar.bz2 |
* 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.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 6 | ||||
-rw-r--r-- | binutils/ar.c | 24 | ||||
-rw-r--r-- | binutils/readelf.c | 3 |
3 files changed, 19 insertions, 14 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index e112966..13d20eb 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +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. + 2007-01-11 H.J. Lu <hongjiu.lu@intel.com> * bucomm.c (template_in_dir): Fix typo. diff --git a/binutils/ar.c b/binutils/ar.c index e48249e..1152242 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -777,10 +777,10 @@ open_inarch (const char *archive_filename, const char *file) 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; } diff --git a/binutils/readelf.c b/binutils/readelf.c index 8f19a32..a4ade9d 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -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]"), |