Fix buffer overflow

This commit is contained in:
Dmitry Stogov 2022-05-26 17:19:43 +03:00
parent 62d7fa7147
commit f5bbdeea27
3 changed files with 2 additions and 4 deletions

View File

@ -4687,7 +4687,7 @@ static void ir_emit_switch(ir_ctx *ctx, int b, ir_ref def, ir_insn *insn)
if ((max.i64-min.i64) < count * 8) {
int *labels = ir_mem_malloc(sizeof(int) * (max.i64 - min.i64 + 1));
for (i = 0; i <= (max.i64 - min.i64 + 1); i++) {
for (i = 0; i <= (max.i64 - min.i64); i++) {
labels[i] = default_label;
}
p = &ctx->cfg_edges[bb->successors];
@ -4803,7 +4803,7 @@ static void ir_emit_switch(ir_ctx *ctx, int b, ir_ref def, ir_insn *insn)
}
|.align aword
|1:
for (i = 0; i <= (max.i64 - min.i64 + 1); i++) {
for (i = 0; i <= (max.i64 - min.i64); i++) {
| .aword =>labels[i]
}
|.code

View File

@ -80,4 +80,3 @@ test:
.qword .L1
.qword .L3
.qword .L4
.qword .L5

View File

@ -60,4 +60,3 @@ test:
.qword .L1
.qword .L3
.qword .L4
.qword .L5