From 31af332f2a1627ae2bd9232baf5837366a481cfe Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 13 Oct 2021 11:44:03 -0700 Subject: Minor fixes in binary type name emitting (#4239) Add an assert on not emitting a null name (which would cause a crash a few lines down on trying to read its bytes). I hit that when writing a buggy pass that updated field names. Also fix the case of a type not having a name but some of its fields having names. We can't test that atm since our text format requires types to have names anyhow, so this is a fix for a possible future where we do allow parsing non-named types. --- src/wasm/wasm-binary.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/wasm/wasm-binary.cpp') diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 9aa18f270..70bc738f6 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -770,7 +770,7 @@ void WasmBinaryWriter::writeNames() { std::vector namedTypes; for (auto& kv : typeIndices) { auto type = kv.first; - if (wasm->typeNames.count(type)) { + if (wasm->typeNames.count(type) && wasm->typeNames[type].name.is()) { namedTypes.push_back(type); } } @@ -906,7 +906,7 @@ void WasmBinaryWriter::writeNames() { std::vector relevantTypes; for (auto& type : types) { if (type.isStruct() && wasm->typeNames.count(type) && - !wasm->typeNames.at(type).fieldNames.empty()) { + !wasm->typeNames[type].fieldNames.empty()) { relevantTypes.push_back(type); } } @@ -1194,6 +1194,7 @@ static int decodeHexNibble(char ch) { } void WasmBinaryWriter::writeEscapedName(const char* name) { + assert(name); if (!strpbrk(name, "\\")) { writeInlineString(name); return; -- cgit v1.2.3