What has become of buff and word and fgetsl?

Matthias Andree matthias.andree at gmx.de
Mon Feb 24 20:52:45 CET 2003


Hi,

I just tried to debug an obscure problem with fgetsl, and I no longer
understand the code.

I have now cleaned up fgetsl.c, whoever expects fgetsl.c to prepend what
was in the buffer prior to the call, will have to be fixed. "make check"
doesn't reveal such code.

I'll let someone else who has more insight into buff/word code clean up
/that/ mess. AFAICT, the buff/word code is way too complex. The
buff_shrink and buff_expand code looks bogus. We don't need all that
complexity. All that buff needs to be is a compound of length and buffer
pointer. The relevant functions are buff_new, buff_delete, and maybe the
str(cpy|cat) or whatever else is actually used. We add abstraction layer
over abstraction layer without documenting anything. The interaction of
buff and word for example I don't understand.

I can no longer maintain that buff/word stuff. :-(


My findings as to the fgetsl bugs are:

xfgets emitted bogus "0-count" (but not EOF) when it bumped into the
buffer capacity. This magically cleared itself up on the next call, I
don't know how. It also tests not the buffer size for validity but
the remaining capacity, which is wrong and caused the bogus "buffer size
blahblah" aborts when crossing that boundary.

The former xfgets code used to append data to the buffer (I don't see
where that's used) and return the amount of octets read. I have changed
the current xfgets code to stomp over whatever is left in the buffer
from a previous call. This passes "make check", so I'll commit right
away, without further questions. I've now fixed the callee. Anything
else will have to be fix in the callers.

Note that fgetsl wouldn't have to be aware of buff at all, a wrapper
could take care of that, but I'm not separating the buff out now.

My fix doesn't really speed things up though :-(

Note you can set the environment variable BOGOFILTER_ABORT_WHEN_CLOBBER
-- if it's defined (even if empty), it will cause bogofilter to abort
when xfgetsl finds a nonempty input buffer. This variable will break the
fgetsl.test self-test code.

-- 
Matthias Andree




More information about the bogofilter-dev mailing list