diff --git a/common/fs.cc b/common/fs.cc index 2f98216e..cfc37618 100644 --- a/common/fs.cc +++ b/common/fs.cc @@ -159,8 +159,24 @@ struct wad_archive : archive_like uint8_t compression; padding<2> pad; std::array name; // must be null terminated + // NOTE: textures using all 16 exist in the wild, e.g. openquartzmirror + // in free_wad.wad auto stream_data() { return std::tie(filepos, disksize, size, type, compression, pad, name); } + + std::string name_as_string() const { + size_t length = 0; + + // count the number of leading non-null characters + for (int i = 0; i < 16; ++i) { + if (name[i] != 0) + ++length; + else + break; + } + + return std::string(name.data(), length); + } }; std::unordered_map, case_insensitive_hash, case_insensitive_equal> @@ -189,7 +205,11 @@ struct wad_archive : archive_like wadstream >= file; - files[file.name.data()] = std::make_tuple(file.filepos, file.disksize); + std::string tex_name = file.name_as_string(); + if (tex_name.size() == 16) { + logging::print("WARNING: texture name {} ({}) is not null-terminated\n", tex_name, pathname); + } + files[tex_name] = std::make_tuple(file.filepos, file.disksize); } }