9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Bseek and Brdline
@ 1995-08-25 11:02 forsyth
  0 siblings, 0 replies; only message in thread
From: forsyth @ 1995-08-25 11:02 UTC (permalink / raw)


the new release appeared to break one of my programs,
and at first i thought it was a bug in new code in Bseek, but it
turns out to be my fault.

the new release changed Bseek to reuse the contents of
the Biobuf when possible, avoiding i/o.
many applications of Brdline, however, have the following form

	while((line = Brdline(f, '\n')) != 0) {
		line[Blinelen(f)-1] = 0;	/* replace '\n' */
		...
	}

this is a bad idea in combination with the new Bseek,
since it removes a newline from buffer contents that
a subsequent Bseek might preserve.  a later Brdline
will appear to malfunction, although it is just following orders.
it will not find the original newline, since it is now 0, and
will either find an untouched newline further down the file
or return an indication that the line seems to be bigger
than the buffer size!

it suffices to restore the '\n' at the end of the loop body,
but there might be more attractive solutions depending on the
application.  it can be tricky to spot, though, if the Brdline
is hidden in a library separate from the program that calls Bseek.






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-08-25 11:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-08-25 11:02 Bseek and Brdline forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).