Преглед на файлове

* fixes widestring range checking, resolves #10013

git-svn-id: trunk@8971 -
florian преди 18 години
родител
ревизия
1bbe6565b0
променени са 3 файла, в които са добавени 53 реда и са изтрити 1 реда
  1. 1 0
      .gitattributes
  2. 1 1
      rtl/inc/wstrings.inc
  3. 51 0
      tests/webtbs/tw10013.pp

+ 1 - 0
.gitattributes

@@ -7598,6 +7598,7 @@ tests/webtbs/tw0961.pp svneol=native#text/plain
 tests/webtbs/tw0965.pp svneol=native#text/plain
 tests/webtbs/tw0966.pp svneol=native#text/plain
 tests/webtbs/tw0976.pp svneol=native#text/plain
+tests/webtbs/tw10013.pp svneol=native#text/plain
 tests/webtbs/tw1021.pp svneol=native#text/plain
 tests/webtbs/tw1023.pp svneol=native#text/plain
 tests/webtbs/tw1041.pp svneol=native#text/plain

+ 1 - 1
rtl/inc/wstrings.inc

@@ -1055,7 +1055,7 @@ end;
 
 Procedure fpc_WideStr_CheckRange(len,index : SizeInt);[Public,Alias : 'FPC_WIDESTR_RANGECHECK']; compilerproc;
 begin
-  if (index>len) or (Index<1) then
+  if (index>len div 2) or (Index<1) then
     HandleErrorFrame(201,get_frame);
 end;
 

+ 51 - 0
tests/webtbs/tw10013.pp

@@ -0,0 +1,51 @@
+program rcerror;
+
+{$MODE DELPHI} {$H+} {$R+}
+
+uses SysUtils;
+
+var
+  ws: WideString;
+  //wc: WideChar;
+  i: Integer;
+
+begin
+  ws := UTF8Decode('something');
+
+  WriteLn;
+  WriteLn('str: "', UTF8Encode(ws), '"');
+  WriteLn('len (must be 9) : ', Length(ws));
+  WriteLn;
+
+  for i := 1 to Length(ws) * 2 + 1 do
+  begin
+
+    Write('Try to access ws[', i, ']');
+
+    try
+
+      ws[i] := ws[i];
+      //wc := ws[i];
+      //ws[i] := wc;
+
+      if i > Length(ws) then
+        begin
+          writeln(' FAULT');
+          halt(1);
+        end
+      else
+        WriteLn(' OK');
+
+    except
+
+      on e : Exception do
+      begin
+        if (e is ERangeError) and (i > Length(ws)) then
+          WriteLn(' OK (got a range-check error as expected)');
+      end;
+
+    end;
+
+  end;
+end.
+