2011-05-20 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / bfd / bfdio.c
index 4c13a767384add1ee9dbf7fe8d5b3b9d39a663c7..dab8e88fb23cf2db09a6c6e9f0438084a9c63e1e 100644 (file)
@@ -1,7 +1,7 @@
 /* Low-level I/O routines for BFDs.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011
    Free Software Foundation, Inc.
 
    Written by Cygnus Support.
@@ -180,8 +180,12 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
   if (abfd->arelt_data != NULL)
     {
       size_t maxbytes = ((struct areltdata *) abfd->arelt_data)->parsed_size;
-      if (size > maxbytes)
-       size = maxbytes;
+      if (abfd->where + size > maxbytes)
+        {
+          if (abfd->where >= maxbytes)
+            return 0;
+          size = maxbytes - abfd->where;
+        }
     }
 
   if (abfd->iovec)
@@ -573,7 +577,7 @@ memory_bstat (bfd *abfd, struct stat *statbuf)
 {
   struct bfd_in_memory *bim = (struct bfd_in_memory *) abfd->iostream;
 
-  memset (statbuf, 0, sizeof (statbuf));
+  memset (statbuf, 0, sizeof (*statbuf));
   statbuf->st_size = bim->size;
 
   return 0;
This page took 0.023788 seconds and 4 git commands to generate.