Browse Source

* fix possible range check errors, resolves #27461

git-svn-id: trunk@29743 -
florian 10 năm trước cách đây
mục cha
commit
726a78be08
2 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 1 1
      compiler/rautils.pas
  2. 4 2
      compiler/symdef.pas

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

+ 4 - 2
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;