Re: [PATCH] SBuf c-string comparisons

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Mon, 21 Apr 2014 09:17:45 -0600

On 04/20/2014 02:08 AM, Amos Jeffries wrote:

> + while ((rv = *left - *right++) == 0) {
> + if (*left++ == '\0' || --byteCount == 0)
> + break;
> + }

> + // If we stopped scanning because we reached the end of buf()
> + if (!byteCount && length() < n)
> + return '\0' - *right;

The comment does not quite match the condition because it ignores the
second part of the condition. The whole condition is closer to something
like "we reached the end of buf() before we reached the end of s". That
"before" part (missing in the comment and difficult to guess) is what
actually makes "right" dereferencing safe in this patch revision AFAICT.

I do not see any bugs in the latest patch, and the above problem can be
fixed during commit IMO. Please do not forget to add test cases (missing
in the latest patch).

Thank you,

Alex.
Received on Mon Apr 21 2014 - 15:18:05 MDT

This archive was generated by hypermail 2.2.0 : Mon Apr 21 2014 - 12:00:13 MDT