summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm-binary-reader.c10
-rw-r--r--src/wasm-binary-writer.c4
2 files changed, 6 insertions, 8 deletions
diff --git a/src/wasm-binary-reader.c b/src/wasm-binary-reader.c
index e95edb0c..160eeb1d 100644
--- a/src/wasm-binary-reader.c
+++ b/src/wasm-binary-reader.c
@@ -328,15 +328,13 @@ static WasmBool skip_until_section(WasmContext* ctx, int section_index) {
return WASM_FALSE;
}
+ WasmStringSlice section_name;
+ in_str(ctx, &section_name, "section name");
in_u32_leb128(ctx, &section_size, "section size");
- uint32_t after_size_offset = ctx->offset;
- if (after_size_offset + section_size > ctx->size)
+ if (ctx->offset + section_size > ctx->size)
RAISE_ERROR(ctx, "invalid section size: extends past end");
- WasmStringSlice section_name;
- in_str(ctx, &section_name, "section name");
-
int index = -1;
#define V(name) \
else if (strncmp(section_name.start, WASM_SECTION_NAME_##name, \
@@ -350,7 +348,7 @@ static WasmBool skip_until_section(WasmContext* ctx, int section_index) {
if (index == -1) {
/* ok, unknown section, skip it. */
- ctx->offset = after_size_offset + section_size;
+ ctx->offset += section_size;
return 0;
} else if (index < section_index) {
RAISE_ERROR(ctx, "section " PRIstringslice " out of order",
diff --git a/src/wasm-binary-writer.c b/src/wasm-binary-writer.c
index 4a33a8a7..c2fbea89 100644
--- a/src/wasm-binary-writer.c
+++ b/src/wasm-binary-writer.c
@@ -250,11 +250,11 @@ static void begin_section(WasmContext* ctx,
char desc[100];
wasm_snprintf(desc, sizeof(desc), "section \"%s\"", name);
write_header(ctx, desc, PRINT_HEADER_NO_INDEX);
- ctx->last_section_offset =
- write_u32_leb128_space(ctx, leb_size_guess, "section size (guess)");
ctx->last_section_leb_size_guess = leb_size_guess;
wasm_snprintf(desc, sizeof(desc), "section id: \"%s\"", name);
write_str(&ctx->stream, name, strlen(name), WASM_DONT_PRINT_CHARS, desc);
+ ctx->last_section_offset =
+ write_u32_leb128_space(ctx, leb_size_guess, "section size (guess)");
}
static void end_section(WasmContext* ctx) {