lkml.org 
[lkml]   [2015]   [Feb]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC][PATCH v2 2/7] implement memmem()
Date
On Fri, Feb 06 2015, Al Viro <viro@ZenIV.linux.org.uk> wrote:

> +/**
> + * strnstr - Find the first substring in a length-limited string
> + * @s1: The string to be searched
> + * @s2: The string to search for
> + * @len: the maximum number of characters to search
> + */
> +char *strnstr(const char *s1, const char *s2, size_t len)
> +{
> + return memmem(s1, len, s2, strlen(s2));
> +}

Most strn* interfaces don't require the n to be at most the actual
string length, but it seems that this would happily search past the '\0'
of s1 if len is large enough, e.g.

strnstr("abc\0def", "def", 1000)

will not return NULL (unlike what the libbsd version does). So either
that restriction should be documented or len should be replaced by
min(len, strlen(s1)).

Rasmus



\
 
 \ /
  Last update: 2015-02-07 00:01    [W:0.103 / U:1.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site