@@ -400,8 +400,7 @@ check_array_type(const WASMModule *module, uint32 type_index, char *error_buf,
400400 error_buf_size)) {
401401 return false;
402402 }
403- if (module->types[type_index] == NULL
404- || module->types[type_index]->type_flag != WASM_TYPE_ARRAY) {
403+ if (module->types[type_index]->type_flag != WASM_TYPE_ARRAY) {
405404 set_error_buf(error_buf, error_buf_size, "unknown array type");
406405 return false;
407406 }
@@ -424,8 +423,7 @@ check_function_type(const WASMModule *module, uint32 type_index,
424423 }
425424
426425#if WASM_ENABLE_GC != 0
427- if (module->types[type_index] == NULL
428- || module->types[type_index]->type_flag != WASM_TYPE_FUNC) {
426+ if (module->types[type_index]->type_flag != WASM_TYPE_FUNC) {
429427 set_error_buf(error_buf, error_buf_size, "unknown function type");
430428 return false;
431429 }
@@ -1257,9 +1255,8 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
12571255 error_buf_size)) {
12581256 goto fail;
12591257 }
1260- if (module->types[type_idx] == NULL
1261- || module->types[type_idx]->type_flag
1262- != WASM_TYPE_STRUCT) {
1258+ if (module->types[type_idx]->type_flag
1259+ != WASM_TYPE_STRUCT) {
12631260 set_error_buf(error_buf, error_buf_size,
12641261 "unknown struct type");
12651262 goto fail;
@@ -2499,6 +2496,13 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
24992496#endif /* end of WASM_ENABLE_GC == 0 */
25002497 }
25012498
2499+ for (i = 0; i < module->type_count; i++) {
2500+ if (module->types[i] == NULL) {
2501+ set_error_buf_v(error_buf, error_buf_size, "unknown type %d", i);
2502+ return false;
2503+ }
2504+ }
2505+
25022506 if (p != p_end) {
25032507 set_error_buf(error_buf, error_buf_size, "section size mismatch");
25042508 return false;
@@ -12685,9 +12689,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1268512689 error_buf, error_buf_size)) {
1268612690 goto fail;
1268712691 }
12688- if (module->types[type_idx1] == NULL
12689- || module->types[type_idx1]->type_flag
12690- != WASM_TYPE_FUNC) {
12692+ if (module->types[type_idx1]->type_flag != WASM_TYPE_FUNC) {
1269112693 set_error_buf(error_buf, error_buf_size,
1269212694 "unknown function type");
1269312695 goto fail;
@@ -12704,9 +12706,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1270412706 error_buf, error_buf_size)) {
1270512707 goto fail;
1270612708 }
12707- if (module->types[type_idx] == NULL
12708- || module->types[type_idx]->type_flag
12709- != WASM_TYPE_FUNC) {
12709+ if (module->types[type_idx]->type_flag != WASM_TYPE_FUNC) {
1271012710 set_error_buf(error_buf, error_buf_size,
1271112711 "unknown function type");
1271212712 goto fail;
@@ -14542,9 +14542,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1454214542 error_buf_size)) {
1454314543 goto fail;
1454414544 }
14545- if (module->types[type_idx] == NULL
14546- || module->types[type_idx]->type_flag
14547- != WASM_TYPE_STRUCT) {
14545+ if (module->types[type_idx]->type_flag
14546+ != WASM_TYPE_STRUCT) {
1454814547 set_error_buf(error_buf, error_buf_size,
1454914548 "unknown struct type");
1455014549 goto fail;
@@ -14630,9 +14629,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1463014629 error_buf_size)) {
1463114630 goto fail;
1463214631 }
14633- if (module->types[type_idx] == NULL
14634- || module->types[type_idx]->type_flag
14635- != WASM_TYPE_STRUCT) {
14632+ if (module->types[type_idx]->type_flag
14633+ != WASM_TYPE_STRUCT) {
1463614634 set_error_buf(error_buf, error_buf_size,
1463714635 "unknown struct type");
1463814636 goto fail;
0 commit comments