Handle cases where the optional import header isn't present :P

This commit is contained in:
Dr. Chat 2017-02-25 20:28:45 -06:00
parent 2bd19478a4
commit ad5748f3e7
1 changed files with 29 additions and 27 deletions

View File

@ -237,9 +237,10 @@ bool XexModule::Load(const std::string& name, const std::string& path,
// Add all imports (variables/functions).
xex2_opt_import_libraries* opt_import_header = nullptr;
GetOptHeader(XEX_HEADER_IMPORT_LIBRARIES, &opt_import_header);
assert_not_null(opt_import_header);
// FIXME: Don't know if 32 is the actual limit, but haven't seen more than 2.
if (opt_import_header) {
// FIXME: Don't know if 32 is the actual limit, but haven't seen more than
// 2.
const char* string_table[32];
std::memset(string_table, 0, sizeof(string_table));
size_t max_string_table_index = 0;
@ -264,13 +265,14 @@ bool XexModule::Load(const std::string& name, const std::string& path,
uint32_t library_offset = 0;
uint32_t library_count = opt_import_header->library_count;
for (uint32_t i = 0; i < library_count; i++) {
auto library =
reinterpret_cast<xex2_import_library*>(libraries_ptr + library_offset);
auto library = reinterpret_cast<xex2_import_library*>(libraries_ptr +
library_offset);
size_t library_name_index = library->name_index & 0xFF;
assert_true(library_name_index < max_string_table_index);
SetupLibraryImports(string_table[library_name_index], library);
library_offset += library->size;
}
}
// Find __savegprlr_* and __restgprlr_* and the others.
// We can flag these for special handling (inlining/etc).