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]

Account for trailing bytes read from bfd_bread


Noticed when debugging the >2G obstack corruption of gdb data.  When
we have a truncated read, we ought to return the amount read.  Not
that it matters very much on an error return..

    	* cache.c (cache_bread_1): Don't return -1 when fread returns
    	a positive value.

diff --git a/bfd/cache.c b/bfd/cache.c
index 27fe70a..ffda004 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -310,7 +310,7 @@ cache_bread_1 (struct bfd *abfd, void *buf, file_ptr nbytes)
   if (nread == (file_ptr)-1)
     {
       bfd_set_error (bfd_error_system_call);
-      return -1;
+      return nread;
     }
 #else
   nread = fread (buf, 1, nbytes, f);
@@ -320,7 +320,7 @@ cache_bread_1 (struct bfd *abfd, void *buf, file_ptr nbytes)
   if (nread < nbytes && ferror (f))
     {
       bfd_set_error (bfd_error_system_call);
-      return -1;
+      return nread;
     }
 #endif
   if (nread < nbytes)

-- 
Alan Modra
Australia Development Lab, IBM


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