[BUG] StandardFileStream #findStringFromEnd: gets wrong position

Richard Staehli rastaehli at mac.com
Sat Aug 9 02:09:54 UTC 2003


I found this bug when trying to open a Package Loader.  The 
SqueakMap.2.log file it tried to open was created with 
StandardFileStream, but I had since changed the default to 
CrLfFileStream.  The bug is in StandardFileStream >> 
findStringFromEnd:.  This method calls #next: to get contents to 
search, but #next: is implemented in CrLfFileStream to substitute cr 
for crlf, which causes location of string match to appear to be earlier 
in the file than it actually is."

| file key |
	file _ (StandardFileStream newFileNamed: 'crlftest.txt').
	file
		nextPut: Character cr;
		nextPut: Character lf;
		nextPutAll: 'marker: 1!';
		close.

	key _ 'marker:'.
	[	"this works!"
		file _ (StandardFileStream oldFileNamed: 'crlftest.txt').
		(file findStringFromEnd: key) = 0
			ifFalse: [
				file skip: key size.
				(file upTo: $!) asNumber inspect.
			].
	] ensure: [file close].
	[	"this does not!"
		file _ (CrLfFileStream oldFileNamed: 'crlftest.txt').
		(file findStringFromEnd: key) = 0
			ifFalse: [
				file skip: key size.
				(file upTo: $!) asNumber inspect.
			].
	] ensure: [file close].

The workaround is not too hard: convert all such old files to CR line 
endings.  The correct fix, however,  is not obvious to me.

Richard



More information about the Squeak-dev mailing list