Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1301558pxa; Sat, 15 Aug 2020 15:03:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsU3fX0CiAJ/ktiCSuKBuIoH903545ffahuxNFgYrFfDoNAharOWnhqd2zA37f7cY0q/zt X-Received: by 2002:a17:906:8506:: with SMTP id i6mr8420784ejx.446.1597528986389; Sat, 15 Aug 2020 15:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597528986; cv=none; d=google.com; s=arc-20160816; b=XSBB0zda9A7OGVKMsImkBkuDpdPwbmhjPgUosjR7D0tmoryoThoqv71WGBBPuRNJpL WKb8ViMtijuwhr0IZaWVNFMl2a9RPH+Z03sXiQVOW9dm5Xygn3+4gDnhVBTDN2t56nhR KJJtQcLZW07XcRUvQO3eTYGhxnfFN2SSCoKdi6ld/Y7uuhWoKvTm9X4vaq+m0f9ByZYX RUnkQhWJ57AzBLTAXSFM7OaSVw9FAPRaY1vhFAgYoK8VDcvUd8J0GqdzQr9M7x7Eky3k g7tqvqE8wD6LVw/mT5YYtsQg1fcuESS9ag8JZxPgTmaH74gZ9iZwrEBgAYdB/CXYlXix dN6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jI8e9DtJD9Qcgx42soPG9jHlS2DsiPdV0uXxPDuNotg=; b=u349VLwCKsLlgXj1210APv0v8Xr6jH/shulHuVO+ZDDw5s3F8v7YJO6xy777xzvUug 7WP+/9BCchZN68ddTVm2K+EyHKQdfiI8nT8Lbo7Y6JErHD8B3PlCKl3nlr8t0mfo1N3C 0RXLj9GhzjLGtLr9m1m+rf8s+jKBnQ+PzHF6e4QmGLD6RRDc6o3iMBknVkSJdxdNo+JB XWg/g1vfoU7FqhSkePWtiTo4QW63lMJI1yI2Hnr/e6hOR5UGXPdfUWSK4YntJdDbxOaH oZKTQoNAzuLNBpaBnK2H+0ar8IrLr5jRVY9+us96VkSArMX/13eWHHVoemrGZfXchVmf ACsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="b5j/+d/S"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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.15.02.43; Sat, 15 Aug 2020 15:03:06 -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=pass header.i=@google.com header.s=20161025 header.b="b5j/+d/S"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729012AbgHOWB2 (ORCPT + 99 others); Sat, 15 Aug 2020 18:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728795AbgHOVva (ORCPT ); Sat, 15 Aug 2020 17:51:30 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA66DC061357 for ; Fri, 14 Aug 2020 19:01:11 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id 2so5215812pjx.5 for ; Fri, 14 Aug 2020 19:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jI8e9DtJD9Qcgx42soPG9jHlS2DsiPdV0uXxPDuNotg=; b=b5j/+d/SR6xrSblNKYVjBhuIMIiKPO3YfhBxKHpYK+mnLaoiNYk2/l70QldOlzNKId XllwItmXSK+pdXDzxM6NCyQJ26LP/Y0CBwCkaLgoo0+g/iU7dIhvJ7sH8UJwinEN5JZB 5bOUXjTYgSwZvSbAJ0VgX2pdbDwASMP+Uu8PEMPKu5PhfRlOTyQ+vQBf9e0M5iGv5+va N4eyu3w0s0UWdJBWXMKWnAuy+uwpRlh1r6AOiZrzW0zlnGaeSdvxKPxsmxoYzY+q84nl EY7q1xYyzOqSMrmqJsi2tN2AUz66JBki14TSgu6EaXSPk2aF9PXdIWjdWad2PD+tLD/X midg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jI8e9DtJD9Qcgx42soPG9jHlS2DsiPdV0uXxPDuNotg=; b=ubP8ztFN6Z/jLnABROV7xgmyxXXPAygQV9OxCq21at6V/ff41U6xiOsfe9bZqH3cJR ktWiQTMGN3/oOBW8EunGHKdRh5tUscqFDrP6rBUJ5T7utwkXPUyeiEZZQApSGtGgH6T7 pM2BOPf7HEaiBIX7otCP9g+qZ3EtyG1RuWi1ddTOIRNRJcsre8TO0vKvjBRNZAyrxRBb y6BDjIXh7imDlLGaTTeOg7AW/2b22Nlb8K1YP0AIFkN1Z4i0MgPDUhyWYK3mLQqs/UzQ F023k0fa3KG2+o0DKgKmUnjUJ6n/pxGaRjd9G6uMXShifVxF3LjbIJUCg8fAIFSZo2NY /s0A== X-Gm-Message-State: AOAM533LK+gu3HUEr1RxqDETp6/n3WtpWhtdoCa19GNnX/+YDyPtjZhC ycHSNzwm86V1r+p5rqkKh3u5eDdQ1F2f1AcrZxCzIg== X-Received: by 2002:a17:90a:a10c:: with SMTP id s12mr4383536pjp.32.1597456871114; Fri, 14 Aug 2020 19:01:11 -0700 (PDT) MIME-Version: 1.0 References: <20200815002417.1512973-1-ndesaulniers@google.com> <20200815013310.GA99152@rani.riverdale.lan> In-Reply-To: <20200815013310.GA99152@rani.riverdale.lan> From: Nick Desaulniers Date: Fri, 14 Aug 2020 19:00:59 -0700 Message-ID: Subject: Re: [PATCH] lib/string.c: implement stpcpy To: Arvind Sankar Cc: Andrew Morton , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , "# 3.4.x" , Sami Tolvanen , Joe Perches , Tony Luck , Yury Norov , Daniel Axtens , Dan Williams , "Joel Fernandes (Google)" , Andy Shevchenko , Kees Cook , Alexandru Ardelean , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" 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 6:33 PM 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. Yep, looks like I had a bug in my test program that masked this. Thanks for triple checking. > > Nit: NUL is more correct than NULL to refer to the string terminator. TIL. -- Thanks, ~Nick Desaulniers