Selaa lähdekoodia

* don't range pointers converted to arrays, resolves #8191

git-svn-id: trunk@8900 -
florian 18 vuotta sitten
vanhempi
commit
ae79ef2cb5
3 muutettua tiedostoa jossa 40 lisäystä ja 1 poistoa
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/ncgmem.pas
  3. 37 0
      tests/webtbs/tw8191.pp

+ 1 - 0
.gitattributes

@@ -8384,6 +8384,7 @@ tests/webtbs/tw8177a.pp -text
 tests/webtbs/tw8180.pp svneol=native#text/plain
 tests/webtbs/tw8183.pp svneol=native#text/plain
 tests/webtbs/tw8187.pp svneol=native#text/plain
+tests/webtbs/tw8191.pp svneol=native#text/plain
 tests/webtbs/tw8195a.pp svneol=native#text/plain
 tests/webtbs/tw8195b.pp svneol=native#text/plain
 tests/webtbs/tw8199.pp svneol=native#text/plain

+ 2 - 1
compiler/ncgmem.pas

@@ -720,7 +720,8 @@ implementation
                   begin
                      if not(is_open_array(left.resultdef)) and
                         not(is_array_of_const(left.resultdef)) and
-                        not(is_dynamic_array(left.resultdef)) then
+                        not(is_dynamic_array(left.resultdef)) and
+                        not(ado_isconvertedpointer in tarraydef(left.resultdef).arrayoptions) then
                        begin
                           if (tordconstnode(right).value.svalue>tarraydef(left.resultdef).highrange) or
                              (tordconstnode(right).value.svalue<tarraydef(left.resultdef).lowrange) then

+ 37 - 0
tests/webtbs/tw8191.pp

@@ -0,0 +1,37 @@
+program PCharRangeChecking;
+
+{$APPTYPE CONSOLE}
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+{$R+}
+
+function Test: Boolean;
+var
+  s: shortstring;
+  p: PChar;
+begin
+  s := '1234567890';
+  p := PChar(@s[1]);
+  Inc(p,4);
+
+  Result :=
+   (p[-4] = '1') and
+   (p[-3] = '2') and
+   (p[-2] = '3') and
+   (p[-1] = '4') and
+   (p[ 0] = '5') and
+   (p[ 1] = '6') and
+   (p[ 2] = '7') and
+   (p[ 3] = '8') and
+   (p[ 4] = '9') and
+   (p[ 5] = '0');
+end;
+
+begin
+  if not Test then
+    halt(1);
+  WriteLn('ok');
+end.