From: Ian Lance Taylor Date: Sun, 29 May 2011 17:17:39 +0000 (+0000) Subject: * binary.cc (Binary_to_elf::sized_convert): Don't crash if the X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=69d53f7ae0536130badf18c159c01fdcd8dfedfc;p=binutils-gdb.git * binary.cc (Binary_to_elf::sized_convert): Don't crash if the binary input file is empty. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 63190c7a321..9e8617b2b53 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,8 @@ +2011-05-29 Ian Lance Taylor + + * binary.cc (Binary_to_elf::sized_convert): Don't crash if the + binary input file is empty. + 2011-05-27 Ian Lance Taylor * testsuite/Makefile.am (ver_test_2.so): Use -Wl,-R,. diff --git a/gold/binary.cc b/gold/binary.cc index f14df0dedf0..6cc99a96935 100644 --- a/gold/binary.cc +++ b/gold/binary.cc @@ -132,7 +132,11 @@ Binary_to_elf::sized_convert(const Task* task) } section_size_type filesize = convert_to_section_size_type(f.filesize()); - const unsigned char* fileview = f.get_view(0, 0, filesize, false, false); + const unsigned char* fileview; + if (filesize == 0) + fileview = NULL; + else + fileview = f.get_view(0, 0, filesize, false, false); unsigned int align; if (size == 32) @@ -223,10 +227,13 @@ Binary_to_elf::sized_convert(const Task* task) shstrtab.get_strtab_size(), 0, 0, 1, 0, &pout); - memcpy(pout, fileview, filesize); - pout += filesize; - memset(pout, 0, aligned_filesize - filesize); - pout += aligned_filesize - filesize; + if (filesize > 0) + { + memcpy(pout, fileview, filesize); + pout += filesize; + memset(pout, 0, aligned_filesize - filesize); + pout += aligned_filesize - filesize; + } this->write_symbol("", &strtab, 0, 0, &pout); this->write_symbol(start_symbol_name, &strtab, 0, 1,