From 615f314969111779bdaffaef0e00d13a0efd51f5 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 15 Oct 2007 02:00:56 +0000 Subject: [PATCH] * objdump.c (print_line): Check fwrite return value. * srconv.c (checksum, wr_tr, wr_cs): Likewise. * sysdump.c (fillup): Return zero on getc or fread EOF. Return count read. --- binutils/ChangeLog | 7 +++++++ binutils/objdump.c | 9 ++++++--- binutils/srconv.c | 14 +++++++++++--- binutils/sysdump.c | 13 ++++++++++--- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index add3ffc57fb..f7b628b4c46 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,10 @@ +2007-10-15 Alan Modra + + * objdump.c (print_line): Check fwrite return value. + * srconv.c (checksum, wr_tr, wr_cs): Likewise. + * sysdump.c (fillup): Return zero on getc or fread EOF. Return count + read. + 2007-10-10 Jim Blandy * dwarf.c (process_debug_info): Line up section offsets of diff --git a/binutils/objdump.c b/binutils/objdump.c index 03bc4d60ae1..ee5530b1464 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1130,14 +1130,17 @@ static void print_line (struct print_file_list *p, unsigned int line) { const char *l; + size_t len; --line; if (line >= p->maxline) return; l = p->linemap [line]; - fwrite (l, 1, strcspn (l, "\n\r"), stdout); - putchar ('\n'); -} + /* Test fwrite return value to quiet glibc warning. */ + len = strcspn (l, "\n\r"); + if (len == 0 || fwrite (l, len, 1, stdout) == 1) + putchar ('\n'); +} /* Print a range of source code lines. */ diff --git a/binutils/srconv.c b/binutils/srconv.c index 914c2607168..2a7d63876a3 100644 --- a/binutils/srconv.c +++ b/binutils/srconv.c @@ -176,7 +176,9 @@ checksum (FILE *file, unsigned char *ptr, int size, int code) /* Glue on a checksum too. */ ptr[bytes] = ~sum; - fwrite (ptr, bytes + 1, 1, file); + if (fwrite (ptr, bytes + 1, 1, file) != 1) + /* FIXME: Return error status. */ + abort (); } @@ -299,7 +301,10 @@ wr_tr (void) 0x03, /* RL */ 0xfd, /* CS */ }; - fwrite (b, 1, sizeof (b), file); + + if (fwrite (b, sizeof (b), 1, file) != 1) + /* FIXME: Return error status. */ + abort (); } static void @@ -1452,7 +1457,10 @@ wr_cs (void) 0x00, /* dot */ 0xDE /* CS */ }; - fwrite (b, 1, sizeof (b), file); + + if (fwrite (b, sizeof (b), 1, file) != 1) + /* FIXME: Return error status. */ + abort (); } /* Write out the SC records for a unit. Create an SC diff --git a/binutils/sysdump.c b/binutils/sysdump.c index 6b3fbdaec04..8387e711f83 100644 --- a/binutils/sysdump.c +++ b/binutils/sysdump.c @@ -119,8 +119,15 @@ fillup (unsigned char *ptr) int sum; int i; - size = getc (file) - 2; - fread (ptr, 1, size, file); + size = getc (file); + if (size == EOF + || size <= 2) + return 0; + + size -= 2; + if (fread (ptr, size, 1, file) != 1) + return 0; + sum = code + size + 2; for (i = 0; i < size; i++) @@ -132,7 +139,7 @@ fillup (unsigned char *ptr) if (dump) dh (ptr, size); - return size - 1; + return size; } static barray -- 2.30.2