Re: [PATCH 4/7] lib: Introduce strnstr()

From: Alex Riesen
Date: Mon Jan 18 2010 - 10:56:14 EST

On Mon, Jan 18, 2010 at 15:53, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Sat, 2010-01-16 at 12:12 +0100, Alex Riesen wrote:
>> Are you sure you want to search _past_ the NUL-terminator
>> of s1?
>> > + Â Â Â l2 = strlen(s2);
>> > + Â Â Â if (!l2)
>> > + Â Â Â Â Â Â Â return (char *)s1;
>> > + Â Â Â while (l1 >= l2) {
>> > + Â Â Â Â Â Â Â l1--;
> The first check is len-1, I don't see it searching past the
> NUL-terminator. The loop will stop when l1 == l2 (the size of s2) and s1
> pointing near the end of the string.

I thought that len means "minimum of strlen(s1) and len".

Li already explained that was not intended, even if s2 cannot be made to
contain a \0, as s1 can by specifying len greater than strlen(s1).
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at