@@ -9693,8 +9693,10 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value,
96939693 *offset = 0;
96949694 return true;
96959695 }
9696- *offset = -(uint32)(ctx->i64_const_num * 2 + ctx->i32_const_num)
9697- + (uint32)(i64_const - ctx->i64_consts) * 2;
9696+
9697+ /* constant index is encoded as negative value */
9698+ *offset = -(int32)(ctx->i64_const_num * 2 + ctx->i32_const_num)
9699+ + (int32)(i64_const - ctx->i64_consts) * 2;
96989700 }
96999701 else if (type == VALUE_TYPE_V128) {
97009702 V128 key = *(V128 *)value, *v128_const;
@@ -9704,9 +9706,12 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value,
97049706 *offset = 0;
97059707 return true;
97069708 }
9707- *offset = -(uint32)(ctx->v128_const_num)
9708- + (uint32)(v128_const - ctx->v128_consts);
9709+
9710+ /* constant index is encoded as negative value */
9711+ *offset = -(int32)(ctx->v128_const_num)
9712+ + (int32)(v128_const - ctx->v128_consts);
97099713 }
9714+
97109715 else {
97119716 int32 key = *(int32 *)value, *i32_const;
97129717 i32_const = bsearch(&key, ctx->i32_consts, ctx->i32_const_num,
@@ -9715,8 +9720,10 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value,
97159720 *offset = 0;
97169721 return true;
97179722 }
9718- *offset = -(uint32)(ctx->i32_const_num)
9719- + (uint32)(i32_const - ctx->i32_consts);
9723+
9724+ /* constant index is encoded as negative value */
9725+ *offset = -(int32)(ctx->i32_const_num)
9726+ + (int32)(i32_const - ctx->i32_consts);
97209727 }
97219728
97229729 return true;
0 commit comments