From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754740AbbBFWzw (ORCPT ); Fri, 6 Feb 2015 17:55:52 -0500 Received: from smtprelay0169.hostedemail.com ([216.40.44.169]:40046 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751246AbbBFWzv (ORCPT ); Fri, 6 Feb 2015 17:55:51 -0500 X-Session-Marker: 6E657665747340676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2282:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3874:4385:5007:6261:7875:7904:10004:10400:10848:10967:11232:11658:11914:12517:12519:12740:13069:13161:13229:13311:13357:14096:14097:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: stage45_32f4a82ec2954 X-Filterd-Recvd-Size: 2418 Date: Fri, 6 Feb 2015 17:55:49 -0500 From: Steven Rostedt To: Rasmus Villemoes Cc: Al Viro , linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH v2 2/7] implement memmem() Message-ID: <20150206175549.117804c2@gandalf.local.home> In-Reply-To: <87zj8qoepw.fsf@rasmusvillemoes.dk> References: <20150205224632.GW29656@ZenIV.linux.org.uk> <1423195215-25134-2-git-send-email-viro@ZenIV.linux.org.uk> <87zj8qoepw.fsf@rasmusvillemoes.dk> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 06 Feb 2015 23:30:19 +0100 Rasmus Villemoes wrote: > 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)). The version that is currently in the kernel will do exactly what the patched version will do. Although it may be different than what libbsd might do, we don't really care. The kernel doc states that @len will be the maximum number of characters to search, and that's exactly what this does. The functionality of strnstr() does not change with this patch, so it does not need to address your concern. Feel free to submit a patch that states the difference of the kernel version of strnstr with whatever version is out in the wild. But that is out of scope with this series. -- Steve