[cvs] bogofilter/src buff.h,1.21,1.22 buff.c,1.27,1.28
David Relson
relson at osagesoftware.com
Sat Jan 8 05:19:38 CET 2005
On Sat, 08 Jan 2005 04:37:09 +0100
Matthias Andree wrote:
> relson at users.sourceforge.net writes:
>
> > +void buff_shift(buff_t *self, uint start, uint length)
> > +{
> > + /* Shift buffer contents to delete the specified segment. */
> > + /* Implemented for deleting html comments. */
> > +
> > + BOGO_ASSERT(start + length <= self->t.leng,
> > + "Invalid buff_shift() parameters.");
> > +
> > + memmove(self->t.text + start, self->t.text + start + length, self->t.leng - length);
> > + self->t.leng -= length;
> > + Z(self->t.text[self->t.leng]); /* for easier debugging - removable */
>
> Watch out for them segfaults, I fixed one of these guys before in buffer
> handling code. Better nuke the Z() macro here so it doesn't scribble
> beyond the buffer.
Not a problem in this case. This function is used to move part of the
buffer towards the beginning of the buffer. The number of interesting
characters in the buffer after a shift is always fewer than the number
before the shift. There's always room for a terminal nul.
To ensure that there's space, "+D" is used when allocating the buffer.
More information about the bogofilter-dev
mailing list