Messages in this thread | | | Date | Mon, 18 Jan 2010 00:47:04 +0100 | Subject | Re: [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator | From | Alex Riesen <> |
| |
On Sat, Jan 16, 2010 at 21:57, André Goddard Rosa <andre.goddard@gmail.com> wrote: > diff --git a/lib/string.c b/lib/string.c > index 0f86245..94bad34 100644 > --- a/lib/string.c > +++ b/lib/string.c > @@ -689,11 +689,13 @@ EXPORT_SYMBOL(strstr); > */ > char *strnstr(const char *s1, const char *s2, size_t len) > { > - size_t l1 = len, l2; > + size_t l1, l2; > > l2 = strlen(s2); > if (!l2) > return (char *)s1; > + l1 = strlen(s1); > + l1 = (l1 <= len) ? l1 : len;
if (l1 > len) l1 = len;
Less code and easier to read. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |