* 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 -
This commit is contained in:
Jonas Maebe 2009-03-22 15:53:16 +00:00
parent 5cf4ab7642
commit 6f4637b32a
3 changed files with 27 additions and 3 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/webtbs/tw13318.pp Normal file
View File

@ -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.