From 29de86703927170785c59fa2c55ecc5bb624ceb2 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 26 Mar 2018 23:30:26 -0500 Subject: [PATCH] Fix bug causing functions with 254 bytes of locals to crash on return. This was a bug with the code for moving the return address. It would generate a "LDA 0" instruction when it was trying to load the value at DP+256. The following program (derived from a csmith-generated test case) demonstrates the crash: #pragma optimize 8 int main (int argc, char **argv) { char s[0xFC]; } --- Gen.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gen.pas b/Gen.pas index 7e39220..7f30571 100644 --- a/Gen.pas +++ b/Gen.pas @@ -5091,7 +5091,7 @@ procedure GenTree {op: icptr}; {if anything needs to be removed from the stack, move the return val} size := localSize + parameterSize; if parameterSize <> 0 then begin - if localSize > 254 then begin + if localSize > 253 then begin GenNative(m_ldx_imm, immediate, localSize+1, nil, 0); GenNative(m_lda_dirx, direct, 0, nil, 0); GenNative(m_ldy_dirx, direct, 1, nil, 0);