[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <81b0412b1001171547s57190f69p489278d1fdf78251@mail.gmail.com>
Date: Mon, 18 Jan 2010 00:47:04 +0100
From: Alex Riesen <raa.lkml@...il.com>
To: André Goddard Rosa <andre.goddard@...il.com>
Cc: linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
Li Zefan <lizf@...fujitsu.com>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH 2/2] string: teach strnstr() to not search past
NUL-terminator
On Sat, Jan 16, 2010 at 21:57, André Goddard Rosa
<andre.goddard@...il.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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists