mirror of
https://github.com/danog/ir.git
synced 2024-11-26 20:34:53 +01:00
Fixed possible invalid write into "prev_insn" after buffer reallocation in ir_next_const()
This commit is contained in:
parent
11db21a98c
commit
c249ccd7ff
19
ir.c
19
ir.c
@ -360,7 +360,7 @@ void ir_free(ir_ctx *ctx)
|
||||
IR_NEVER_INLINE ir_ref ir_const(ir_ctx *ctx, ir_val val, uint8_t type)
|
||||
{
|
||||
ir_insn *insn, *prev_insn;
|
||||
ir_ref ref;
|
||||
ir_ref ref, prev;
|
||||
|
||||
if (type == IR_BOOL) {
|
||||
return val.u64 ? IR_TRUE : IR_FALSE;
|
||||
@ -382,16 +382,17 @@ IR_NEVER_INLINE ir_ref ir_const(ir_ctx *ctx, ir_val val, uint8_t type)
|
||||
ref = insn->prev_const;
|
||||
}
|
||||
|
||||
if (prev_insn) {
|
||||
prev = prev_insn->prev_const;
|
||||
prev_insn->prev_const = -ctx->consts_count;
|
||||
} else {
|
||||
prev = ctx->prev_const_chain[type];
|
||||
ctx->prev_const_chain[type] = -ctx->consts_count;
|
||||
}
|
||||
|
||||
ref = ir_next_const(ctx);
|
||||
insn = &ctx->ir_base[ref];
|
||||
|
||||
if (prev_insn) {
|
||||
insn->prev_const = prev_insn->prev_const;
|
||||
prev_insn->prev_const = ref;
|
||||
} else {
|
||||
insn->prev_const = ctx->prev_const_chain[type];
|
||||
ctx->prev_const_chain[type] = ref;
|
||||
}
|
||||
insn->prev_const = prev;
|
||||
|
||||
insn->optx = IR_OPT(type, type);
|
||||
insn->val.u64 = val.u64;
|
||||
|
Loading…
Reference in New Issue
Block a user