From e42be0deebb0f1c55cf5adebc48224a4e0638428 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 24 Jul 2022 19:50:56 -0500 Subject: [PATCH] Avoid overflow in computation of whether a case statement is sparse. If the difference between the minimum and maximum values in a case statement was greater than 32767, then the subtraction in this computation would overflow. That would cause the case statement to be treated as non-sparse, so a jump table would be generated for it, but that jump table would be very large, so it would overflow the object buffer and cause an error. --- parser.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.pas b/parser.pas index 560d322..718148d 100644 --- a/parser.pas +++ b/parser.pas @@ -3737,7 +3737,7 @@ end; {DoConstant} Gen1(dc_lab, lcix); if fstptr <> nil then begin {if there are labels...} lmin := fstptr^.cslab; - if (lmax - lmin) div lcount > sparse then begin + if (ord4(lmax) - lmin) div lcount > sparse then begin {use if-else for sparse case statements} while fstptr <> nil do begin