bfd
[deliverable/binutils-gdb.git] / bfd / compress.c
index a526ea99c79822c171edce34106c27c354006a7f..a82a8bc9e3cb205ef6b881fc73b91ff1eda8709d 100644 (file)
@@ -1,5 +1,5 @@
 /* Compressed section support (intended for debug sections).
-   Copyright 2008, 2010
+   Copyright 2008, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -100,6 +100,9 @@ bfd_compress_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
   compressed_size = compressBound (uncompressed_size) + 12;
   compressed_buffer = (bfd_byte *) bfd_malloc (compressed_size);
 
+  if (compressed_buffer == NULL)
+    return FALSE;
+
   if (compress ((Bytef*) compressed_buffer + 12,
                &compressed_size,
                (const Bytef*) uncompressed_buffer,
@@ -155,7 +158,7 @@ DESCRIPTION
 bfd_boolean
 bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
 {
-  bfd_size_type sz = sec->rawsize ? sec->rawsize : sec->size;
+  bfd_size_type sz;
   bfd_byte *p = *ptr;
 #ifdef HAVE_ZLIB_H
   bfd_boolean ret;
@@ -166,6 +169,10 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
   bfd_byte *uncompressed_buffer;
 #endif
 
+  if (abfd->direction != write_direction && sec->rawsize != 0)
+    sz = sec->rawsize;
+  else
+    sz = sec->size;
   if (sz == 0)
     return TRUE;
 
This page took 0.023218 seconds and 4 git commands to generate.