While finding the bug #12897 I found that a memory stream position could be set to before the start of the file without giving an error, and subsequent reads would appear to work (unless the position was so far off an invalid region of memory was read). I found the precise problem by patching TCustomMemoryStream to raise an exception if the position is set before the start of the file. Should an exception be raised in this circumstance, which would make finding bugs easier? Or should the position just be set to 0, which would be more consistent with the behaviour when going beyond the end of the stream?
See attached patch for the sort of thing I am thinking of. Colin
diff -uNr --exclude=.svn --exclude='*.rst' trunk/fpcsrc/rtl/objpas/classes/streams.inc trunk.w/fpcsrc/rtl/objpas/classes/streams.inc --- trunk/fpcsrc/rtl/objpas/classes/streams.inc 2008-07-21 23:56:12.000000000 +0100 +++ trunk.w/fpcsrc/rtl/objpas/classes/streams.inc 2008-12-31 17:46:05.000000000 +0000 @@ -521,9 +521,15 @@ Case Origin of soFromBeginning : FPosition:=Offset; soFromEnd : FPosition:=FSize+Offset; - soFromCurrent : FpoSition:=FPosition+Offset; + soFromCurrent : FPosition:=FPosition+Offset; end; + if FPosition < 0 then + {$IFDEF DEBUG} + raise Exception.Create('TCustomMemoryStream'); + {$ELSE} + FPosition := 0; + {$ENDIF} Result:=FPosition; end;
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel