Browse Source

Merge commits 39912, 39914, 40001, 40115, 40132 and 40163
------------------------------------------------------------------------
r39912 | pierre | 2018-10-11 22:38:39 +0200 (Thu, 11 Oct 2018) | 1 line

Fix ppuload for string type for i8086, use getasizeint for all string defs but short string
------------------------------------------------------------------------
------------------------------------------------------------------------
r39914 | pierre | 2018-10-12 08:05:50 +0200 (Fri, 12 Oct 2018) | 1 line

Adapt ppudump to fix introduced in revision 39912
------------------------------------------------------------------------
------------------------------------------------------------------------
r40001 | pierre | 2018-10-21 00:19:08 +0200 (Sun, 21 Oct 2018) | 1 line

Add explicit typecast to avoid range check error
------------------------------------------------------------------------
------------------------------------------------------------------------
r40115 | pierre | 2018-10-31 23:53:11 +0100 (Wed, 31 Oct 2018) | 1 line

Avoid range check error in ReadPosInfo
------------------------------------------------------------------------
------------------------------------------------------------------------
r40132 | pierre | 2018-11-01 08:09:47 +0100 (Thu, 01 Nov 2018) | 1 line

Only call moved if len>0, as otherwise astring local variable is nil, which leads to a range check error for astring[1]
------------------------------------------------------------------------
------------------------------------------------------------------------
r40163 | pierre | 2018-11-01 22:58:54 +0100 (Thu, 01 Nov 2018) | 8 lines

More -CriotR fixes:
* entfile.pas: Change PPU header falgs filed from longint to dword.
* ngtcon.pas: Change local variable startoffset type to aword.
* omfbase.pas: Avoid calling move with a nil string s indexed as s[1],
to avoid a range check error.
* owomflib.pas: Disable range check explicitly in hash computation.
* utils/ppuutils/ppudump.pp: Adapt to flags type change in entfile.pas

------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@40519 -

pierre 6 years ago
parent
commit
6205e530aa

+ 2 - 2
compiler/entfile.pas

@@ -192,8 +192,8 @@ type
     compiler : word;
     compiler : word;
     cpu      : word;
     cpu      : word;
     target   : word;
     target   : word;
-    flags    : longint;
-    size     : longint; { size of the ppufile without header }
+    flags    : dword;
+    size     : dword; { size of the ppufile without header }
   end;
   end;
   pentryheader=^tentryheader;
   pentryheader=^tentryheader;
 
 

+ 1 - 1
compiler/ngtcon.pas

@@ -1519,7 +1519,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
         bp   : tbitpackedval;
         bp   : tbitpackedval;
         error,
         error,
         is_packed: boolean;
         is_packed: boolean;
-        startoffset: aint;
+        startoffset: aword;
 
 
       procedure handle_stringconstn;
       procedure handle_stringconstn;
         begin
         begin

+ 18 - 9
compiler/omfbase.pas

@@ -1349,18 +1349,23 @@ implementation
         internalerror(2015033103);
         internalerror(2015033103);
       SetLength(s, len);
       SetLength(s, len);
       UniqueString(s);
       UniqueString(s);
-      Move(RawData[Offset+1],s[1],len);
+      if len>0 then
+        Move(RawData[Offset+1],s[1],len);
     end;
     end;
 
 
   function TOmfRawRecord.WriteStringAt(Offset: Integer; s: string): Integer;
   function TOmfRawRecord.WriteStringAt(Offset: Integer; s: string): Integer;
+    var
+      len : longint;
     begin
     begin
-      if Length(s)>255 then
+      len:=Length(s);
+      if len>255 then
         internalerror(2015033101);
         internalerror(2015033101);
-      result:=Offset+Length(s)+1;
+      result:=Offset+len+1;
       if result>High(RawData) then
       if result>High(RawData) then
         internalerror(2015033102);
         internalerror(2015033102);
-      RawData[Offset]:=Length(s);
-      Move(s[1], RawData[Offset+1], Length(s));
+      RawData[Offset]:=len;
+      if len>0 then
+        Move(s[1], RawData[Offset+1], len);
     end;
     end;
 
 
   function TOmfRawRecord.ReadIndexedRef(Offset: Integer; out IndexedRef: Integer): Integer;
   function TOmfRawRecord.ReadIndexedRef(Offset: Integer; out IndexedRef: Integer): Integer;
@@ -1420,7 +1425,7 @@ implementation
       b:=0;
       b:=0;
       for I:=-3 to RecordLength-2 do
       for I:=-3 to RecordLength-2 do
         b:=byte(b+RawData[I]);
         b:=byte(b+RawData[I]);
-      SetChecksumByte($100-b);
+      SetChecksumByte(byte($100-b));
     end;
     end;
 
 
   function TOmfRawRecord.VerifyChecksumByte: boolean;
   function TOmfRawRecord.VerifyChecksumByte: boolean;
@@ -1521,14 +1526,18 @@ implementation
     end;
     end;
 
 
   procedure TOmfRecord_COMENT.EncodeTo(RawRecord: TOmfRawRecord);
   procedure TOmfRecord_COMENT.EncodeTo(RawRecord: TOmfRawRecord);
+    var
+      len : longint;
     begin
     begin
       RawRecord.RecordType:=RT_COMENT;
       RawRecord.RecordType:=RT_COMENT;
-      if (Length(FCommentString)+3)>High(RawRecord.RawData) then
+      len:=Length(FCommentString);
+      if (len+3)>High(RawRecord.RawData) then
         internalerror(2015033105);
         internalerror(2015033105);
-      RawRecord.RecordLength:=Length(FCommentString)+3;
+      RawRecord.RecordLength:=len+3;
       RawRecord.RawData[0]:=CommentType;
       RawRecord.RawData[0]:=CommentType;
       RawRecord.RawData[1]:=CommentClass;
       RawRecord.RawData[1]:=CommentClass;
-      Move(FCommentString[1],RawRecord.RawData[2],Length(FCommentString));
+      if len>0 then
+        Move(FCommentString[1],RawRecord.RawData[2],len);
       RawRecord.CalculateChecksumByte;
       RawRecord.CalculateChecksumByte;
     end;
     end;
 
 

+ 4 - 0
compiler/owomflib.pas

@@ -421,6 +421,9 @@ implementation
             repeat
             repeat
               pb:=@blocks[h.block_x];
               pb:=@blocks[h.block_x];
               success:=false;
               success:=false;
+	      {$push}
+	      { Disable range check in that part of code }
+	      {$R-}
               repeat
               repeat
                 if pb^[h.bucket_x]=0 then
                 if pb^[h.bucket_x]=0 then
                   begin
                   begin
@@ -440,6 +443,7 @@ implementation
                   end;
                   end;
                 h.bucket_x:=(h.bucket_x+h.bucket_d) mod nbuckets;
                 h.bucket_x:=(h.bucket_x+h.bucket_d) mod nbuckets;
               until h.bucket_x=start_bucket;
               until h.bucket_x=start_bucket;
+	      {$pop}
               if not success then
               if not success then
                 begin
                 begin
                   h.block_x:=(h.block_x+h.block_d) mod nblocks;
                   h.block_x:=(h.block_x+h.block_d) mod nblocks;

+ 4 - 4
compiler/symdef.pas

@@ -2421,7 +2421,7 @@ implementation
       begin
       begin
          inherited ppuload(stringdef,ppufile);
          inherited ppuload(stringdef,ppufile);
          stringtype:=st_ansistring;
          stringtype:=st_ansistring;
-         len:=ppufile.getaint;
+         len:=ppufile.getasizeint;
          encoding:=ppufile.getword;
          encoding:=ppufile.getword;
          ppuload_platform(ppufile);
          ppuload_platform(ppufile);
       end;
       end;
@@ -2447,7 +2447,7 @@ implementation
            encoding:=CP_UTF16LE
            encoding:=CP_UTF16LE
          else
          else
            encoding:=CP_UTF16BE;
            encoding:=CP_UTF16BE;
-         len:=ppufile.getaint;
+         len:=ppufile.getasizeint;
          ppuload_platform(ppufile);
          ppuload_platform(ppufile);
       end;
       end;
 
 
@@ -2468,7 +2468,7 @@ implementation
       begin
       begin
          inherited ppuload(stringdef,ppufile);
          inherited ppuload(stringdef,ppufile);
          stringtype:=st_unicodestring;
          stringtype:=st_unicodestring;
-         len:=ppufile.getaint;
+         len:=ppufile.getasizeint;
          encoding:=ppufile.getword;
          encoding:=ppufile.getword;
          ppuload_platform(ppufile);
          ppuload_platform(ppufile);
       end;
       end;
@@ -2505,7 +2505,7 @@ implementation
             ppufile.putbyte(byte(len))
             ppufile.putbyte(byte(len))
            end
            end
          else
          else
-           ppufile.putaint(len);
+           ppufile.putasizeint(len);
          if stringtype in [st_ansistring,st_unicodestring] then
          if stringtype in [st_ansistring,st_unicodestring] then
            ppufile.putword(encoding);
            ppufile.putword(encoding);
          case stringtype of
          case stringtype of

+ 13 - 11
compiler/utils/ppuutils/ppudump.pp

@@ -537,10 +537,10 @@ begin
 end;
 end;
 
 
 
 
-function PPUFlags2Str(flags:longint):string;
+function PPUFlags2Str(flags:dword):string;
 type
 type
   tflagopt=record
   tflagopt=record
-    mask : longint;
+    mask : dword;
     str  : string[30];
     str  : string[30];
   end;
   end;
 const
 const
@@ -578,10 +578,11 @@ const
     (mask: $10000000;str:'i8086_cs_equals_ds'),
     (mask: $10000000;str:'i8086_cs_equals_ds'),
     (mask: $20000000;str:'package_deny'),
     (mask: $20000000;str:'package_deny'),
     (mask: $40000000;str:'package_weak'),
     (mask: $40000000;str:'package_weak'),
-    (mask: longint($80000000);str:'i8086_ss_equals_ds')
+    (mask: dword($80000000);str:'i8086_ss_equals_ds')
   );
   );
 var
 var
-  i,ntflags : longint;
+  i : longint;
+  ntflags : dword;
   first  : boolean;
   first  : boolean;
   s : string;
   s : string;
 begin
 begin
@@ -1051,7 +1052,7 @@ begin
      Writeln([fileindex,' (',line,',',column,')']);
      Writeln([fileindex,' (',line,',',column,')']);
      if Def <> nil then
      if Def <> nil then
        begin
        begin
-         Def.FilePos.FileIndex:=fileindex - 1;
+         Def.FilePos.FileIndex:=fileindex;
          Def.FilePos.Line:=line;
          Def.FilePos.Line:=line;
          Def.FilePos.Col:=column;
          Def.FilePos.Col:=column;
        end;
        end;
@@ -1812,7 +1813,8 @@ begin
               begin
               begin
                 len:=gettokenbufsizeint;
                 len:=gettokenbufsizeint;
                 setlength(astring,len);
                 setlength(astring,len);
-                move(tokenbuf[tbi],astring[1],len);
+                if len>0 then
+                  move(tokenbuf[tbi],astring[1],len);
                 write([' ',astring]);
                 write([' ',astring]);
                 inc(tbi,len);
                 inc(tbi,len);
               end;
               end;
@@ -2595,7 +2597,7 @@ begin
                    write  ([space,'  PointerType : ']);
                    write  ([space,'  PointerType : ']);
                    readderef('',constdef.TypeRef);
                    readderef('',constdef.TypeRef);
                    constdef.ConstType:=ctInt;
                    constdef.ConstType:=ctInt;
-                   constdef.VInt:=getptruint;
+                   constdef.VInt:=int64(getptruint);
                    writeln([space,'        Value : ',constdef.VInt])
                    writeln([space,'        Value : ',constdef.VInt])
                  end;
                  end;
                conststring,
                conststring,
@@ -3306,7 +3308,7 @@ begin
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef.StrType:=stWide;
              strdef.StrType:=stWide;
              readcommondef('WideString definition',defoptions,strdef);
              readcommondef('WideString definition',defoptions,strdef);
-             strdef.Len:=getaint;
+             strdef.Len:=getasizeint;
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'           Length : ',strdef.Len]);
            end;
            end;
 
 
@@ -3315,7 +3317,7 @@ begin
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef.StrType:=stUnicode;
              strdef.StrType:=stUnicode;
              readcommondef('UnicodeString definition',defoptions,strdef);
              readcommondef('UnicodeString definition',defoptions,strdef);
-             strdef.Len:=getaint;
+             strdef.Len:=getasizeint;
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'         Encoding : ',getword]);
              writeln([space,'         Encoding : ',getword]);
            end;
            end;
@@ -3325,7 +3327,7 @@ begin
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef.StrType:=stAnsi;
              strdef.StrType:=stAnsi;
              readcommondef('AnsiString definition',defoptions,strdef);
              readcommondef('AnsiString definition',defoptions,strdef);
-             strdef.Len:=getaint;
+             strdef.Len:=getasizeint;
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'         Encoding : ',getword]);
              writeln([space,'         Encoding : ',getword]);
            end;
            end;
@@ -3335,7 +3337,7 @@ begin
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef:=TPpuStringDef.Create(ParentDef);
              strdef.StrType:=stLong;
              strdef.StrType:=stLong;
              readcommondef('Longstring definition',defoptions,strdef);
              readcommondef('Longstring definition',defoptions,strdef);
-             strdef.Len:=getaint;
+             strdef.Len:=getasizeint;
              writeln([space,'           Length : ',strdef.Len]);
              writeln([space,'           Length : ',strdef.Len]);
            end;
            end;