Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1299052pxa; Sat, 15 Aug 2020 14:57:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQkVJRBhj8XMqSVnZfMe3NsBbBpcM9DqRuRwpGNdj7yO0SrkI9w10SYm20z/JUx2+M4MZs X-Received: by 2002:a50:9d88:: with SMTP id w8mr8130614ede.122.1597528623940; Sat, 15 Aug 2020 14:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597528623; cv=none; d=google.com; s=arc-20160816; b=yoqpJim3VW2oI3kcZi+8xJxvbcuJorPkNdHZieilXUkGN3bBUABBFo77qZsPbZlO4s iuXyNNV79CWPJFmanntqE+D4Ny0EHabdGV81OnvM2Y/O4AAIXcRJJsOazJo9VcAHT7Pv H0Cz6u+QtHQ8wUdQQNlr1/vwqiDTbj6glcp62Hq5GXQmDxCHSepd+fRipNEdQnhNxRJY il0Cu27C1ACm93xjJ/GwpUWFmfZrCr7WNRL8sfMSFoFD4gpFqpQBl6wh3GjvZbZmfI3V zQOEO11i5QSkF7IFRQWeD5l4pMHMXoPMyeoSIrEZYpc1xR+n29WNaYseg5086pI6soS/ sf4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=/LJPODsukhk9ilKQ5Nhku7oJFNIdXYTCpu7/+RHvulw=; b=WILWfJbiO77tCsbAM+dv0rgFQ7fZeX24O6TJcJVeno8El+QooJknyCGwAmqEYcDqFT cqewMP0VDjIZSA+J4PwvGQhJ/6oR4Bgl7uuX4vW9qQlPWnk/HANo/ggUV9FaOtG7aj7O iUnSBYgGRXKbmHQ/537dlWgIVp+8QrCkXY5twK6EWm7IJY2zFvjFxaJDjH5sS+Tx71t2 nCfOp9nQgHz+OoVUEtQqwbVxkGerYdZQz6/TIGhcwRrJacpqGo35BV8jbNHqA8xlHAAU RH6VZCsNUyXISltqlO1D0o9sv6PdSa7A/uk0GKw9FN8pbnsyjpHp9e0PtH1kp3rwZObm wdZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=nLw79+rm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si6857668ede.29.2020.08.15.14.56.41; Sat, 15 Aug 2020 14:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=nLw79+rm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbgHOVzV (ORCPT + 99 others); Sat, 15 Aug 2020 17:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729082AbgHOVwZ (ORCPT ); Sat, 15 Aug 2020 17:52:25 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7C2C06134E; Fri, 14 Aug 2020 18:40:10 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id s16so8363579qtn.7; Fri, 14 Aug 2020 18:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/LJPODsukhk9ilKQ5Nhku7oJFNIdXYTCpu7/+RHvulw=; b=nLw79+rmoA2nElv+xnAFz8nXs/AlqzKnFWwt843zJ3flzcKUwV86WHPBtEYbGdl5NP pnqjP3u+xb17yJYfFXiutjt5y02NnTJhiiK+ZWvPo1FnjYjhvPeBe3k8ZDAidXu43QGq LbWjjCzzatkcCYFiRlFEBJFcPjmZx9Fgp5T/gy4C+x8ofCMVUTXcQS2wYBKnAMzgLLDl N3sNkBhDhQOg6mxoqkBrL4ooaXdjWLbuTEkNTdFlLF3gIpRqhFuBfOXvKMB+hx9XziB0 r1Jr4Dar9TLw3jf6AXi2DhpbsoYTRIVyi3C5kYBH4EczNGf1VF+SSu0DtQBoYNU1CoYe mucQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=/LJPODsukhk9ilKQ5Nhku7oJFNIdXYTCpu7/+RHvulw=; b=lstCFHrmSlFJg/onNcoL1XX4e25IpL/hmpg3514jSmxI1eSsTk/tkDDUK1Kx/foNyQ lwz6Vu9XuSOcEhd7ynpEDawpzoQ1yDB+a6bcNTMIIVFR7wg6oT3mpcNZwCoXIe9wjvpZ LdSRYxFO19hyZhVUy1blD6kM2RFeALJ4Soug8vW9uDeV9CaSeOZOhgztXII1/Key80g5 fynfYBI6APR+bBPgHO4eHh0aS7AMYRUK/GZQodrD/U6H2A9bOOmjxUI91BBiOnmrs/CX 2lTBBCMZWV4WT22i8rm0H7hm80LQNs2VTbikKy0UiEy1VL+/MBiT9o2zOyPDygPbbTZm 0cPA== X-Gm-Message-State: AOAM533cp/9KF5gEc5Ts+u5cTo013aK1dl+EUEuK54Ov1fbFXXaRBdOZ jpn3M8HClDAcyKpvI1i15R8= X-Received: by 2002:aed:3789:: with SMTP id j9mr4809739qtb.251.1597455608719; Fri, 14 Aug 2020 18:40:08 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id d124sm9846309qkg.65.2020.08.14.18.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 18:40:08 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 14 Aug 2020 21:40:06 -0400 To: Arvind Sankar Cc: Nick Desaulniers , Andrew Morton , =?utf-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , stable@vger.kernel.org, Sami Tolvanen , Joe Perches , Tony Luck , Yury Norov , Daniel Axtens , Dan Williams , "Joel Fernandes (Google)" , Andy Shevchenko , Kees Cook , Alexandru Ardelean , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] lib/string.c: implement stpcpy Message-ID: <20200815014006.GB99152@rani.riverdale.lan> References: <20200815002417.1512973-1-ndesaulniers@google.com> <20200815013310.GA99152@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200815013310.GA99152@rani.riverdale.lan> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 14, 2020 at 09:33:10PM -0400, Arvind Sankar wrote: > On Fri, Aug 14, 2020 at 05:24:15PM -0700, Nick Desaulniers wrote: > > +#ifndef __HAVE_ARCH_STPCPY > > +/** > > + * stpcpy - copy a string from src to dest returning a pointer to the new end > > + * of dest, including src's NULL terminator. May overrun dest. > > + * @dest: pointer to end of string being copied into. Must be large enough > > + * to receive copy. > > + * @src: pointer to the beginning of string being copied from. Must not overlap > > + * dest. > > + * > > + * stpcpy differs from strcpy in two key ways: > > + * 1. inputs must not overlap. > > + * 2. return value is the new NULL terminated character. (for strcpy, the > > + * return value is a pointer to src. > > + */ > > +#undef stpcpy > > +char *stpcpy(char *__restrict__ dest, const char *__restrict__ src) > > +{ > > + while ((*dest++ = *src++) != '\0') > > + /* nothing */; > > + return dest; > > +} > > +#endif > > + > > Won't this return a pointer that's one _past_ the terminating NUL? I > think you need the increments to be inside the loop body, rather than as > part of the condition. > > Nit: NUL is more correct than NULL to refer to the string terminator. Also, strcpy (at least the one in the C standard) is undefined if the strings overlap, so that's not really a difference.