Browse Source

* synchronized with trunk

git-svn-id: branches/wasm@48451 -
nickysn 4 years ago
parent
commit
e7d568ea38
4 changed files with 27 additions and 3 deletions
  1. 1 0
      .gitattributes
  2. 10 1
      compiler/nmem.pas
  3. 12 0
      tests/webtbs/tw38413.pp
  4. 4 2
      utils/fpdoc/dwriter.pp

+ 1 - 0
.gitattributes

@@ -18713,6 +18713,7 @@ tests/webtbs/tw38385.pp svneol=native#text/pascal
 tests/webtbs/tw38390.pp svneol=native#text/pascal
 tests/webtbs/tw38390.pp svneol=native#text/pascal
 tests/webtbs/tw3840.pp svneol=native#text/plain
 tests/webtbs/tw3840.pp svneol=native#text/plain
 tests/webtbs/tw3841.pp svneol=native#text/plain
 tests/webtbs/tw3841.pp svneol=native#text/plain
+tests/webtbs/tw38413.pp svneol=native#text/pascal
 tests/webtbs/tw3863.pp svneol=native#text/plain
 tests/webtbs/tw3863.pp svneol=native#text/plain
 tests/webtbs/tw3864.pp svneol=native#text/plain
 tests/webtbs/tw3864.pp svneol=native#text/plain
 tests/webtbs/tw3865.pp svneol=native#text/plain
 tests/webtbs/tw3865.pp svneol=native#text/plain

+ 10 - 1
compiler/nmem.pas

@@ -1051,7 +1051,16 @@ implementation
                         and not is_64bit(right.resultdef)
                         and not is_64bit(right.resultdef)
 {$endif not cpu64bitaddr}
 {$endif not cpu64bitaddr}
                         then
                         then
-                       newordtyp:=Torddef(right.resultdef).ordtype
+                        begin
+                          { in case of an integer type, we need a new type which covers declaration range and index range,
+                            see tests/webtbs/tw38413.pp
+                          }
+                          if is_integer(right.resultdef) then
+                            newordtyp:=range_to_basetype(min(TConstExprInt(Tarraydef(left.resultdef).lowrange),torddef(right.resultdef).low),
+                              max(TConstExprInt(Tarraydef(left.resultdef).highrange),torddef(right.resultdef).high))
+                          else
+                            newordtyp:=Torddef(right.resultdef).ordtype;
+                        end
                      else
                      else
                        newordtyp:=torddef(sizesinttype).ordtype;
                        newordtyp:=torddef(sizesinttype).ordtype;
                      inserttypeconv(right,corddef.create(newordtyp,
                      inserttypeconv(right,corddef.create(newordtyp,

+ 12 - 0
tests/webtbs/tw38413.pp

@@ -0,0 +1,12 @@
+var
+  arr : array[-1..140] of byte=(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+    4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+    4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
+  index , value : byte; // unsigned byte - important
+begin
+  index:=133; // positive value, which is treated as negative
+  value:=arr[index]; // wrong value! Memory access outside array
+  if value<>4 then
+    halt(1);
+  writeln('ok');
+end.

+ 4 - 2
utils/fpdoc/dwriter.pp

@@ -1067,7 +1067,7 @@ function TLongNameFileAllocator.GetFilename(AElement: TPasElement; ASubindex: In
 var
 var
   n,s: String;
   n,s: String;
   i: Integer;
   i: Integer;
-
+  MElement: TPasElement;
 begin
 begin
   Result:='';
   Result:='';
   if AElement.ClassType = TPasPackage then
   if AElement.ClassType = TPasPackage then
@@ -1105,7 +1105,9 @@ begin
     end else
     end else
       Result := LowerCase(AElement.PathName);
       Result := LowerCase(AElement.PathName);
     // cut off Package Name
     // cut off Package Name
-    AElement:= AElement.GetModule;
+    MElement:= AElement.GetModule;
+    if Assigned(MElement) then
+      AElement:= MElement;
     Result := Copy(Result, Length(AElement.Parent.Name) + 2, MaxInt);
     Result := Copy(Result, Length(AElement.Parent.Name) + 2, MaxInt);
     // to skip dots in unit name
     // to skip dots in unit name
     i := Length(AElement.Name);
     i := Length(AElement.Name);