* bfdio.c (bfd_seek): Formatting. Ensure newly allocated memory
authorAlan Modra <amodra@gmail.com>
Sun, 24 May 2009 11:47:27 +0000 (11:47 +0000)
committerAlan Modra <amodra@gmail.com>
Sun, 24 May 2009 11:47:27 +0000 (11:47 +0000)
       for BFD_IN_MEMORY is cleared.
       (bfd_bwrite): Zero excess memory allocated.

bfd/ChangeLog
bfd/bfdio.c

index 6e5652f22b48d63234770edd0822ae57a88fa855..217b96ca7cb343899b31741667f875151379d5ba 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-24  Alan Modra  <amodra@bigpond.net.au>
+
+       * bfdio.c (bfd_seek): Formatting.  Ensure newly allocated memory
+       for BFD_IN_MEMORY is cleared.
+       (bfd_bwrite): Zero excess memory allocated.
+
 2009-05-22  Julian Brown  <julian@codesourcery.com>
 
        * elf32-arm.c (THUMB16_BCOND_INSN, THUMB32_INSN, THUMB32_B_INSN): New
index d3a295c214d7503a75d4055d34f26dc7b4128539..16bbf03a6970b619ed3d57dcb008f120a98c399c 100644 (file)
@@ -235,6 +235,8 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
                  bim->size = 0;
                  return 0;
                }
+             if (newsize > bim->size)
+               memset (bim->buffer + bim->size, 0, newsize - bim->size);
            }
        }
       memcpy (bim->buffer + abfd->where, ptr, (size_t) size);
@@ -342,8 +344,8 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
 
       if (abfd->where > bim->size)
        {
-         if ((abfd->direction == write_direction) ||
-             (abfd->direction == both_direction))
+         if (abfd->direction == write_direction
+             || abfd->direction == both_direction)
            {
              bfd_size_type newsize, oldsize;
 
@@ -359,6 +361,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
                      bim->size = 0;
                      return -1;
                    }
+                 memset (bim->buffer + oldsize, 0, newsize - oldsize);
                }
            }
          else