You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello everyone, don't you think the fuction ringbuf_findchr should return -1 if there is no match ?
Ror now it return 0 if there is no match and if the match is at index 0.
The text was updated successfully, but these errors were encountered:
ringbuf_findchr returns ringbuf_bytes_used when there is no match, so it only returns 0 when the ring buffer is empty. (If the ring buffer is not empty and there is no match, then the value returned will be > 0.)
It is expected that you will compare the value returned by ringbuf_findchr to the value returned by ringbuf_bytes_used to determine whether a match has been found, e.g.:
If you compare the two values with <, then there is no ambiguity.
The reason that ringbuf_findchr returns ringbuf_bytes_used when there is no match, rather than returning -1 or some other sentinel value, is so that the type of the returned value can be size_t rather than ssize_t; and the reason for that is for type safety, since ringbuf_findchr itself takes size_t offset values. (Negative offsets make no sense.)
So while this convention is slightly clumsier and a bit more expensive than checking for -1 (because this convention requires an additional call to ringbuf_bytes_used), I think it's worth the type safety.
However, in retrospect, this is all a bit confusing, and I should probably make a note of this convention in the documentation.
hello everyone, don't you think the fuction ringbuf_findchr should return -1 if there is no match ?
Ror now it return 0 if there is no match and if the match is at index 0.
The text was updated successfully, but these errors were encountered: