diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-05 11:24:50 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-05 11:24:50 -0700 |
commit | 559c3372cfc68a338a204f58cb5e559a35f4ae4b (patch) | |
tree | 84a3117ce6471a96bce382f85073fe0ac0a63570 /src/wasm-binary.h | |
parent | 155223a2a0dd222817881dab85fa11166cc5bbb3 (diff) | |
download | binaryen-559c3372cfc68a338a204f58cb5e559a35f4ae4b.tar.gz binaryen-559c3372cfc68a338a204f58cb5e559a35f4ae4b.tar.bz2 binaryen-559c3372cfc68a338a204f58cb5e559a35f4ae4b.zip |
reorder section size location in binary format, see design#639
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 5695cffcc..70ee7fe29 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -486,9 +486,8 @@ public: int32_t startSection(const char* name) { // emit 5 bytes of 0, which we'll fill with LEB later - auto ret = writeU32LEBPlaceholder(); writeInlineString(name); - return ret; + return writeU32LEBPlaceholder(); } void finishSection(int32_t start) { @@ -1135,9 +1134,8 @@ public: // read sections until the end while (more()) { - auto sectionSize = getU32LEB(); - assert(sectionSize < pos + input.size()); auto nameSize = getU32LEB(); + uint32_t sectionSize, before; auto match = [&](const char* name) { for (size_t i = 0; i < nameSize; i++) { if (pos + i >= input.size()) return false; @@ -1145,7 +1143,11 @@ public: if (input[pos + i] != name[i]) return false; } if (strlen(name) != nameSize) return false; + // name matched, read section size and then section itself pos += nameSize; + sectionSize = getU32LEB(); + before = pos; + assert(pos + sectionSize < input.size()); return true; }; if (match(BinaryConsts::Section::Start)) readStart(); @@ -1164,6 +1166,7 @@ public: } else { abort(); } + assert(pos == before + sectionSize); } processFunctions(); |