On Fri, Mar 31, 2017 at 02:45:15PM +0200, Christopher Faulet wrote:
> > These situations cause trouble when not using the proper arithmetics. Either
> > all the computations are made without wrapping, or all are made with 
> > wrapping.
> > Any mix of the two causes issues.
> > 
> 
> Yes, of course. I implicitly considered them as special cases of the
> wrapping ones. From the moment you use pointers (bi_ptr/bi_end and
> bo_ptr/bo_end), it is easier. But, it never hurts to mention it :)

In fact it depends how the wrapping is detected. If you just want to measure
a length, wrapping can become cumbersome. For example, detecting this case is
trivial without wrapping :

     buf->p+buf->i == buf->data+buf->size

But it's difficult with wrapping as it's more or less bi_end(p) == data &&
i > 0. Detecting that you've reached the right side of the buffer when
reading one char at a time also makes this not always convenient. In fact
it sometimes happens when you need to add an extra hypothetical length to
the equation to check if a string can be appended.

So there are many places where we purposely don't use them (no need to
spend cycles taking care of wrapping when just comparing two pointers,
or where not wrapping leaves less cases to consider) so I preferred to
mention it here so that other contributors reading this right now or
reading the archives later know that these two methods must never be
mixed and that these special cases can easily become traps.

Willy

Reply via email to