You are not logged in.
Pages: 1
Hello,
I have seen an issue using TRawByteStringStream.Write.
I did write a integer value, after, several string values, and finally I set the TRawByteStringStream Position to 0 and did write a new integer value to the beginning of the stream. My surprise was that the TRawByteStringStream Size was cutted.
I think that there is a problem with the SetLength in this method :
function TRawByteStringStream.Write(const Buffer; Count: Integer): Longint;
begin
if Count<=0 then
Result := 0 else begin
Result := Count;
SetLength(fDataString,fPosition+Result);
{$ifdef FPC}Move{$else}MoveFast{$endif}(Buffer,PByteArray(fDataString)[fPosition],Result);
inc(FPosition,Result);
end;
end;
The SetLength is set although the fPosition+Result not be greater than the length of fDataString.
Is it done thinking in performance?.
Would not be more correct this? :
function TRawByteStringStream.Write(const Buffer; Count: Longint): Longint;
begin
if Count<=0 then
Result := 0
else begin
Result := Count;
if fPosition+Result > Length(fDataString) then
SetLength(fDataString,fPosition+Result);
{$ifdef FPC}Move{$else}MoveFast{$endif}(Buffer,PByteArray(fDataString)[fPosition],Result);
inc(FPosition,Result);
end;
end;
Thank you.
Last edited by macc2010 (2020-02-07 21:29:18)
Offline
Thank you.
Offline
Pages: 1