Browse Source

* check if optinfo is assigned before using it, resolves #39913

florian 2 years ago
parent
commit
2b48afe151
2 changed files with 33 additions and 1 deletions
  1. 1 1
      compiler/optdfa.pas
  2. 32 0
      tests/webtbs/tw39913.pp

+ 1 - 1
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

+ 32 - 0
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.