Przeglądaj źródła

* do not do anything when writing to a t(custom)memorystream if the current
position is negative (patch by Collin Western, mantis #13318)

git-svn-id: trunk@12955 -

Jonas Maebe 16 lat temu
rodzic
commit
6f4637b32a
3 zmienionych plików z 27 dodań i 3 usunięć
  1. 1 0
      .gitattributes
  2. 7 3
      rtl/objpas/classes/streams.inc
  3. 19 0
      tests/webtbs/tw13318.pp

+ 1 - 0
.gitattributes

@@ -8802,6 +8802,7 @@ tests/webtbs/tw13307.pp svneol=native#text/plain
 tests/webtbs/tw1331.pp svneol=native#text/plain
 tests/webtbs/tw13313.pp svneol=native#text/plain
 tests/webtbs/tw13313a.pp svneol=native#text/plain
+tests/webtbs/tw13318.pp svneol=native#text/plain
 tests/webtbs/tw1333.pp svneol=native#text/plain
 tests/webtbs/tw13343.pp svneol=native#text/plain
 tests/webtbs/tw13345x.pp svneol=native#text/plain

+ 7 - 3
rtl/objpas/classes/streams.inc

@@ -505,7 +505,7 @@ function TCustomMemoryStream.Read(var Buffer; Count: Longint): Longint;
 
 begin
   Result:=0;
-  If (FSize>0) and (FPosition<Fsize) then
+  If (FSize>0) and (FPosition<Fsize) and (FPosition>=0) then
     begin
     Result:=FSize-FPosition;
     If Result>Count then Result:=Count;
@@ -521,9 +521,13 @@ begin
   Case Origin of
     soFromBeginning : FPosition:=Offset;
     soFromEnd       : FPosition:=FSize+Offset;
-    soFromCurrent   : FpoSition:=FPosition+Offset;
+    soFromCurrent   : FPosition:=FPosition+Offset;
   end;
   Result:=FPosition;
+  {$IFDEF DEBUG}
+  if Result < 0 then
+    raise Exception.Create('TCustomMemoryStream');
+  {$ENDIF}
 end;
 
 
@@ -643,7 +647,7 @@ function TMemoryStream.Write(const Buffer; Count: Longint): Longint;
 Var NewPos : Longint;
 
 begin
-  If Count=0 then
+  If (Count=0) or (FPosition<0) then
     exit(0);
   NewPos:=FPosition+Count;
   If NewPos>Fsize then

+ 19 - 0
tests/webtbs/tw13318.pp

@@ -0,0 +1,19 @@
+program fpctest4;
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+uses
+  Classes;
+
+var 
+  f:TStream;
+  l: longint;
+begin
+   l:=1;
+   f:=TMemoryStream.Create;
+   f.position:=-1;
+   if (f.write(l,4)<>0) then
+     halt(1);
+   f.free;
+end.