lkml.org 
[lkml]   [2010]   [Jan]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    SubjectRe: [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator
    From
    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/

    \
     
     \ /
      Last update: 2010-01-18 00:59    [W:0.022 / U:0.228 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site