From 726a78be086a1328f6cb1e2a3c04ce062e597d9f Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 17 Feb 2015 21:14:47 +0000 Subject: [PATCH] * fix possible range check errors, resolves #27461 git-svn-id: trunk@29743 - --- compiler/rautils.pas | 2 +- compiler/symdef.pas | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rautils.pas b/compiler/rautils.pas index 9ac136e76d..15496e41b4 100644 --- a/compiler/rautils.pas +++ b/compiler/rautils.pas @@ -1205,7 +1205,7 @@ Begin begin if tconstsym(srsym).consttyp=constord then Begin - l:=tconstsym(srsym).value.valueord.svalue; + l:=aint(tconstsym(srsym).value.valueord.svalue); SearchIConstant:=TRUE; exit; end; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 4511681563..a093f81120 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -3420,8 +3420,10 @@ implementation constructor tarraydef.create_from_pointer(def:tpointerdef); begin - { use -1 so that the elecount will not overflow } - self.create(0,high(asizeint)-1,ptrsinttype); + { divide by the element size and do -1 so the array will have a valid size, + further, the element size might be 0 e.g. for empty records, so use max(...,1) + to avoid a division by zero } + self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,ptrsinttype); arrayoptions:=[ado_IsConvertedPointer]; setelementdef(def.pointeddef); end;