diff options
Diffstat (limited to 'tools/parse_module.c')
-rw-r--r-- | tools/parse_module.c | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/tools/parse_module.c b/tools/parse_module.c index 75329f8..3f9895c 100644 --- a/tools/parse_module.c +++ b/tools/parse_module.c @@ -2,39 +2,11 @@ #include "wasm_compile.h" #include "wasm.h" -static inline int is_valid_valtype(char value_type) -{ - if (value_type == VALTYPE_I32) - return 1; - - if (value_type == VALTYPE_I64 || - value_type == VALTYPE_F32 || - value_type == VALTYPE_F64) - PRERR("Only type i32 is recognized for now"); - - return -1; - - /* return */ - /* value_type == VALTYPE_I32 || */ - /* value_type == VALTYPE_I64 || */ - /* value_type == VALTYPE_F32 || */ - /* value_type == VALTYPE_F64; */ -} - -static inline int is_valid_exportdesc(char desc) -{ - return - desc == EXPORT_FUNCIDX || - desc == EXPORT_TABLEIDX || - desc == EXPORT_MEMIDX || - desc == EXPORT_GLOBALIDX; -} - -int leb_u32(FILE *handle, uint32_t *result) +int leb_32(FILE *handle, uint32_t *result, bool with_sign) { int i, j; int encoded[5]; - uint64_t decoded; + int64_t decoded; for (i = 0; i < 5; i++) { encoded[i] = fgetc(handle); @@ -53,12 +25,17 @@ int leb_u32(FILE *handle, uint32_t *result) } } - decoded = 0; + if (with_sign && encoded[i] & (1 << 6)) + decoded = -1; + else + decoded = 0; for (j = i; j >= 0; j--) decoded = (decoded << 7) | (encoded[j] & 0x7F); - if (decoded > UINT32_MAX) { + if ((with_sign && decoded > INT32_MAX) || + (with_sign && decoded < INT32_MIN) || + (!with_sign && decoded > UINT32_MAX)) { PRERR(MSG_BAD_NUM_ENC); return -1; } @@ -105,6 +82,8 @@ void free_module(struct module *module) free(module->exports); + free_targets(module->targets); + free(module); } @@ -602,7 +581,7 @@ struct module *parse_module(FILE *handle) /* check magic number */ if (memcmp(initial, magic, 4)) { - PRERR("Bad magic number"); + PRERR("Bad magic number\n"); goto fail; } |