From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755753AbbBFWaY (ORCPT ); Fri, 6 Feb 2015 17:30:24 -0500 Received: from mail-lb0-f178.google.com ([209.85.217.178]:35815 "EHLO mail-lb0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754468AbbBFWaX (ORCPT ); Fri, 6 Feb 2015 17:30:23 -0500 From: Rasmus Villemoes To: Al Viro Cc: Steven Rostedt , linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH v2 2/7] implement memmem() Organization: D03 References: <20150205224632.GW29656@ZenIV.linux.org.uk> <1423195215-25134-2-git-send-email-viro@ZenIV.linux.org.uk> X-Hashcash: 1:20:150206:linux-kernel@vger.kernel.org::ClYPscWFNVmiICVX:0000000000000000000000000000000000+UN X-Hashcash: 1:20:150206:viro@zeniv.linux.org.uk::QIJTPBbubdok+tyu:000000000000000000000000000000000000007Bjx X-Hashcash: 1:20:150206:rostedt@goodmis.org::pqsEqITdJaPIiqP+:0000000000000000000000000000000000000000009qBp Date: Fri, 06 Feb 2015 23:30:19 +0100 In-Reply-To: <1423195215-25134-2-git-send-email-viro@ZenIV.linux.org.uk> (Al Viro's message of "Fri, 6 Feb 2015 04:00:10 +0000") Message-ID: <87zj8qoepw.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 06 2015, Al Viro 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