From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 601C13858CDB for ; Thu, 9 Nov 2023 10:13:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 601C13858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=jguk.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jguk.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 601C13858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699524810; cv=none; b=Nkxb41TxqLwF2qbV7bT8fsOTgygAu5iW5S9j5Am41WtaN595Nhn/yz7tHUMVT1QngmJBx1dI7AsC1ShdUNteRr7B75adW4DnLO4Sw/0BKwmtStvs33jJ43FYoISNmht9wk+WBqym3QOY78e6WirlQN1cAoo4MUrXX1YqXPqR1bY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699524810; c=relaxed/simple; bh=22TXV3L6Taruzh9pb8sKOfzxM/vjP1co5lROMjJei4Q=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=SZByeKVurIx86T/K+qh0fKvM7R6vPe5f3Wedp66AO2vj/95yEs481nc/R0m0/do7tZdPO9nSWO1yPA8ZwLVZxJCl7fICEyYC07kDJyMp8nSUJ1dZPjfkanQ0VnsG8imIakhQ9JOcYqjyiCt3AdRf/qGyGOR7V1mGsPwRehvylbg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50797cf5b69so822543e87.2 for ; Thu, 09 Nov 2023 02:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jguk.org; s=google; t=1699524806; x=1700129606; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wMNrkAhv//Hbkoy69DjLzz/hNr0Q/ePPTqKiPCtUVfA=; b=Ts2zbJXcKwlEsU/0Znn2d3ZO8E+eorMZURHHkieSI/G32/NTx+vcOajkigAzfwaSrT a3rdjTOyBK3/b2SdinyUTFK/3Y8mEIcSXsCUIIkylmBvI1trBfgxGbBwdTOFiKmO3+Cp SJXK5YslhC5UEUb0oYVOHqYXIeekL7ppKr77kncLvVpMTxseg4uQVAczgM2BTdLoJwQk iBPB99sfwzCAwHYQDiPRzK3Awe2r0xnIw8709tdNjDIBH3SpNyWrzAXjBdn9m2g9aAmg SkqfjYCUmTd9wcmjM9zfCzl50hYLc69VutpG4lnm4OrR7HGIRm0JRtHcbn73mLaX8XOf sJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524806; x=1700129606; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wMNrkAhv//Hbkoy69DjLzz/hNr0Q/ePPTqKiPCtUVfA=; b=XLkdud3OLckht+CiuId2JXq3a2pZUHnXiMIcbGJcMvFq+LHkure4USIrQt5kiaPp84 Jsxs30zt6gUbNrCXst8IV3dgOHLfQ7LnTQ4so0wSFtZq8Ry8AqTjMqFUGt713fB6JEOr LEVZivzJMYgD422mIpHy+5hVxju9sPjuYFiajE53U+nuABdrOYmXoh+AzYZZMQySntQr IRcxMJjdq96GJtNu26ln88mbT4lOn6I5xFwGI07Eg71Zjd6U1dxUZ/w4JutGNhU5SHUU JXVR0FO+/hOqhgY4ywnymmH7K0ZHUCI8cEIxIQrNCDXIVK5s9m7jZVxQuxahnLEslpSf RZWw== X-Gm-Message-State: AOJu0Yx16xhCCMyFjw4e6niqSfwLNOYFcPevRkxbhqmyhi/sTdZys19z 9aPMXH3jIarT5s0JnBOiF5QMEA== X-Google-Smtp-Source: AGHT+IEXqQicqNwMzeQPZCh4xGZ13xAw4xJ7e0Bd0cp8Cl1LQU006lEMJVjgZVMTzfpnBgDChxINlA== X-Received: by 2002:a05:6512:3053:b0:507:a003:57a2 with SMTP id b19-20020a056512305300b00507a00357a2mr1198956lfb.52.1699524806312; Thu, 09 Nov 2023 02:13:26 -0800 (PST) Received: from [192.168.0.12] (cpc87345-slou4-2-0-cust172.17-4.cable.virginm.net. [81.101.252.173]) by smtp.gmail.com with ESMTPSA id o13-20020a05600c378d00b003fbe4cecc3bsm1589759wmr.16.2023.11.09.02.13.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Nov 2023 02:13:25 -0800 (PST) Message-ID: Date: Thu, 9 Nov 2023 10:13:24 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: strncpy clarify result may not be null terminated Content-Language: en-GB To: Alejandro Colomar , Paul Eggert Cc: Carlos O'Donell , Zack Weinberg , GNU libc development , 'linux-man' References: <929865e3-17b4-49c4-8fa9-8383885e9904@jguk.org> <16cc15a4-cfc0-49f4-9ebf-ecf0901700ce@app.fastmail.com> <8ebee0fc-1e77-41d9-8feb-8c1083a30a93@cs.ucla.edu> From: Jonny Grant In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 09/11/2023 00:29, Alejandro Colomar wrote: > Hi Pail, > > On Wed, Nov 08, 2023 at 03:31:38PM -0800, Paul Eggert wrote: >> On 11/8/23 14:11, Alejandro Colomar wrote: >>> I just don't think we need, >>> as GNU or Linux projects, to be restricted to the decisions of ISO. We >>> can realize that certain functions are bad, and mark them as deprecated >>> in our scope. >> >> There's enough use of strncpy for the intended use (smallish fixed size >> character arrays that are null padded, not null terminated) that saying it's >> deprecated would likely cause more trouble than it's worth. It's not just >> utmp and tar; it's also socket programming (sun_path) and I'm sure other >> stuff. >> >> Were we designing the C library from scratch I'd agree with you: in that >> context, strncpy would clearly be more trouble than it's worth. But now that >> we're stuck with strncpy we have better things to do than try to deprecate >> it. > > No, no, I'm not trying to deprecate it. I was just saying that *iff* > all of its uses were dead, I'd deprecate it. But they're clearly not > dead, so it's a perfect function for those cases. > >> >> Instead of saying "deprecate" I suggest we say something like "This function >> is generally a poor choice for processing strings" and point to the longer >> man page about strings in general. That's what the glibc manual does and it >> works reasonably well. > > Yes, I've done something like this. string_copying(7) recommends > avoiding fixed-width null-padded buffers in APIs. But for those use > cases that already exist, this is the function to use. https://man7.org/linux/man-pages/man7/string_copying.7.html Rather than "catenation", in my experience "concatenation" is the common term to explain what it does. There are quite a few on that page. Probably other man pages too. How about following the style of the other man pages that put the notes about each function below them? (rather than above) https://man7.org/linux/man-pages/man3/string.3.html size_t strlen(const char *s); Return the length of the string s. At the moment on string_copying there are // comments on the line above each function. So the presentation of the information is different: // Copy/catenate a string. char *strcpy(char *restrict dst, const char *restrict src); char *strcat(char *restrict dst, const char *restrict src); Kind regards Jonny