From 6fa5dbadce1f54d96e44c195167016278621ace1 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 19 Jun 2023 22:35:22 +0200 Subject: regalloc: alloc extra memory for alloc map regalloc itself can insert instructions so this was causing out of bounds read errors --- regalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regalloc.c b/regalloc.c index c3afe70..ed5af2c 100644 --- a/regalloc.c +++ b/regalloc.c @@ -257,7 +257,7 @@ regalloc(struct function *fn) struct rega ra = {0}; vinit(&stkslotrefs, stkslotrefsbuf, arraylength(stkslotrefsbuf)); - ra.allocs = xcalloc(ninstr * sizeof(struct alloc)); + ra.allocs = xcalloc((ninstr*2 < MAXINSTR ? ninstr*2 : MAXINSTR) * sizeof(struct alloc)); ra.nfreegpr = mctarg->ngpr - popcnt(mctarg->rglob->u); ra.nfreefpr = mctarg->nfpr; for (int i = 0; i < MAXREGS; ++i) -- cgit v1.2.3