Extract get_uncompressed_size
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 4 Apr 2015 14:49:35 +0000 (07:49 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 4 Apr 2015 14:49:35 +0000 (07:49 -0700)
* compress.c (get_uncompressed_size): New.  Extracted from ...
(bfd_init_section_decompress_status): This.  Use it.

bfd/ChangeLog
bfd/compress.c

index 810705f996655df0e1e6dbb81cd94e8654c155a1..654408e2d8f41378d5d256ff65fac8fdea6af16e 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * compress.c (get_uncompressed_size): New.  Extracted from ...
+       (bfd_init_section_decompress_status): This.  Use it.
+
 2015-04-02  Andrew Turner  <andrew@freebsd.org>
 
        * config.bfd: Add aarch64-*-freebsd* target triple.
index 7e498fac3d6b8fe14b59c75153688f1bbbca1942..6621dffb2793c0140a3d7106be60fd6a8f6af841 100644 (file)
@@ -59,6 +59,27 @@ decompress_contents (bfd_byte *compressed_buffer,
   return rc == Z_OK && strm.avail_out == 0;
 }
 
+static bfd_size_type
+get_uncompressed_size (bfd_byte *uncompressed_size_buffer)
+{
+  bfd_size_type uncompressed_size = uncompressed_size_buffer[0];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[1];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[2];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[3];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[4];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[5];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[6];
+  uncompressed_size <<= 8;
+  uncompressed_size += uncompressed_size_buffer[7];
+  return uncompressed_size;;
+}
+
 /* Compress data of the size specified in @var{uncompressed_size}
    and pointed to by @var{uncompressed_buffer} using zlib and store
    as the contents field.  This function assumes the contents
@@ -347,15 +368,7 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
       return FALSE;
     }
 
-  uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
-  uncompressed_size += compressed_buffer[11];
-
+  uncompressed_size = get_uncompressed_size (compressed_buffer + 4);
   sec->compressed_size = sec->size;
   sec->size = uncompressed_size;
   sec->compress_status = DECOMPRESS_SECTION_SIZED;