summaryrefslogtreecommitdiff
path: root/gold/binary.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2011-05-29 17:17:39 +0000
committerIan Lance Taylor <ian@airs.com>2011-05-29 17:17:39 +0000
commit69d53f7ae0536130badf18c159c01fdcd8dfedfc (patch)
tree59db8426c6d152d7c81542cf7f0dbb7ca13b8795 /gold/binary.cc
parentb3c88224d55e96d3fbfe54b6d151714c3e0564a2 (diff)
downloadbinutils-gdb-69d53f7ae0536130badf18c159c01fdcd8dfedfc.tar.gz
* binary.cc (Binary_to_elf::sized_convert): Don't crash if the
binary input file is empty.
Diffstat (limited to 'gold/binary.cc')
-rw-r--r--gold/binary.cc17
1 files changed, 12 insertions, 5 deletions
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<size, big_endian>("", &strtab, 0, 0, &pout);
this->write_symbol<size, big_endian>(start_symbol_name, &strtab, 0, 1,