From 2b48afe151a41943520040852a7d075968ff1bf6 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 21 Oct 2022 21:14:39 +0200 Subject: [PATCH] * check if optinfo is assigned before using it, resolves #39913 --- compiler/optdfa.pas | 2 +- tests/webtbs/tw39913.pp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw39913.pp diff --git a/compiler/optdfa.pas b/compiler/optdfa.pas index 84309f962e..ecfaa9cc8d 100644 --- a/compiler/optdfa.pas +++ b/compiler/optdfa.pas @@ -888,7 +888,7 @@ unit optdfa; exit; include(node.flags,nf_processing); - if not(DFASetIn(node.optinfo^.life,nodetosearch.optinfo^.index)) then + if not(assigned(node.optinfo)) or not(DFASetIn(node.optinfo^.life,nodetosearch.optinfo^.index)) then exit; { we do not need this info always, so try to safe some time here, CheckAndWarn diff --git a/tests/webtbs/tw39913.pp b/tests/webtbs/tw39913.pp new file mode 100644 index 0000000000..426e1e15b8 --- /dev/null +++ b/tests/webtbs/tw39913.pp @@ -0,0 +1,32 @@ +{ %opt=-O3 } +{$mode objfpc}{$H+} + +type + TDynCardinalArray = array of Cardinal; + +function Test(N: Cardinal): TDynCardinalArray; +var + L: Cardinal; +begin + SetLength(Result, 0); + if N <= 1 then + Exit + else + begin + L := 0; + if N mod 2 = 0 then + begin + Inc(L); + SetLength(Result, L); + Result[L - 1] := 2; + end; + Inc(L); + SetLength(Result, L); + Result[L - 1] := N; + end; +end; + +begin + Test(2); + WriteLn('OK'); +end.