diff --git a/.gitattributes b/.gitattributes index 16eaea2ee1..2765d5b3df 100644 --- a/.gitattributes +++ b/.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 diff --git a/rtl/objpas/classes/streams.inc b/rtl/objpas/classes/streams.inc index 79be57ccd2..ab98c2425b 100644 --- a/rtl/objpas/classes/streams.inc +++ b/rtl/objpas/classes/streams.inc @@ -505,7 +505,7 @@ function TCustomMemoryStream.Read(var Buffer; Count: Longint): Longint; begin Result:=0; - If (FSize>0) and (FPosition0) 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 diff --git a/tests/webtbs/tw13318.pp b/tests/webtbs/tw13318.pp new file mode 100644 index 0000000000..3bffe324fd --- /dev/null +++ b/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.