From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SbfgM2hFg2oBTS0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 13:31:20 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=tQ7hybTl; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CF74D1E0A3; Mon, 17 Aug 2026 13:31:20 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1B4711E09B for ; Mon, 17 Aug 2026 13:31:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A92D34BAE7F3 for ; Mon, 17 Aug 2026 17:31:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A92D34BAE7F3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=tQ7hybTl Received: from YQZPR01CU011.outbound.protection.outlook.com (mail-canadaeastazlp170100000.outbound.protection.outlook.com [IPv6:2a01:111:f403:c104::]) by sourceware.org (Postfix) with ESMTPS id AC52D4BAE7F3; Mon, 17 Aug 2026 17:30:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC52D4BAE7F3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC52D4BAE7F3 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c104:: ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786987853; cv=pass; b=Vj93EGGC8F5P/eFA0c4XgcE5e/IFUCEn1vekH7nuWsi1Qn/wLsG9RjAWBbxT6zKq8J1OO6RMX+I9eX3XWm6lTL7RF+ENYioISoOyUf1jTj5ceJmi1s4xKd8E+UosK7XWQJaXo3adhXtldUMBypHJSLIf0rVnhoq7GqlzC90pxpI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786987853; c=relaxed/simple; bh=458MkmHM8y7ISdS602vufwYYVEvm+vhxZuU/PzOfc9g=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=vFgjbBV2Hlw44LcIXaqPu4MXElX5PWLSSlUqrb+mfeMG8C7bR61W8Ywl6zBcR4Zk8DKfWt8mbBt7wL8YNTLyH0DdrbmlqK/fVxSehAb10C5nX4g3RpoJ+ctc+J3I0fSRXm75nxsr2QpIHOACCUwNNoiBamCVe3CP84g2rx2hUnQ= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=tQ7hybTl DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC52D4BAE7F3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y1UVglwVshIo54j/SETK1RRGKQaP+4ylC9I4MBiddewMT9MfISci8dPPFL5p2t2e1XGTB9EV4TWhq5eRPLshqaMBQAsjh6FshJmiEfVllgjFkIOC3iaUOnxqaKePophM9QUFh7MRABL/R+zHrlhJEK5Rj27OW7BM/v7LAGZRPHemx6x04daCeJfttAVU2OgsJH6laRC34JsogfMoGayALf4uEy23gxu+xHnuu0+I2mqlIgcisbG3G+7oXPvKHXqI+RWkQCjUa/lrPJT+nLQROJGdiLYyyykUcwB/CcsAGir9EEiFyGCDSKSKAxOiQQTwh1s7p6msy1t2/MnwDaGNRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VsdytV3MVjSLq8U+6C+wQWfF6EK8n5Lr5NieET+AfdI=; b=i94fxRyMORDTNUn8PPDzTIXr3qDM3E+ye8f0vhzuw8kCWT5LAzqgI34die3LCOUXVSC0K9QOcF9+f+F8i61PgMbpeaxfaFrNp3LyM1lQ/vlepj5rGbzdsJ6zVM3FBntZp5wuPYGcyrnbEAMcrL3qru7MxVka21YkWQCXORrOPcOC3yKIoPCBkWFBPdqwRB3+GntZnktnENLAKf56PbVP4D/afLGi2dFtXMYPEHu/8Y81qOk3qz3zUp79d15BLNuXS8hbFwcHNL5VOMoH7HgUn/VY1EqlCZ8cOxBoO+AxdoWFrA/MjHWrlnedcb3+v/NNVVrJ3ngMyltKnnkAq0CIhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VsdytV3MVjSLq8U+6C+wQWfF6EK8n5Lr5NieET+AfdI=; b=tQ7hybTl4KLEcDRS9f0YGgFqrl7BRctJWGpKzuyABJMYIdq8ATTabTnvBuoRl8YUXLrrkrb7gnbn4oxpoKWY7h4hQnQiPq1DqDH0vENarH0K2e/wPEhA+BhEKhJPwPes5YdnuUO9je0yRVzu1evHFxdZu6hJlY4b0WnaZqOxCZDohWJAwpCbKujh3zw3TQyXGE+1Vpk1eRdrnJwM/sXZPzJZ/HlYx4tQJHdX6ZWsg2fO5DKDuBT2wszqy/Dsz6JImRUnElrsYAlrzqmypePV+Ai7l8rsypDFktju5GWg4qkENZtC4h/h7kG82EXCnjvOtyyF9fwm2wrdbb3HtB0HGA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=efficios.com; Received: from YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:2c::6) by YT3PR01MB10752.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:98::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.315.17; Mon, 17 Aug 2026 17:30:47 +0000 Received: from YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM ([fe80::bbfa:179f:fdc8:b15d]) by YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM ([fe80::bbfa:179f:fdc8:b15d%7]) with mapi id 15.21.0315.016; Mon, 17 Aug 2026 17:30:45 +0000 Message-ID: <81ece47e-5901-49db-b468-89e0b247367f@efficios.com> Date: Mon, 17 Aug 2026 13:30:44 -0400 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 10/13] gdbsupport: add xstrcpy To: Andrew Burgess , gdb-patches@sourceware.org, binutils@sourceware.org References: <20260817151646.152571-1-simon.marchi@efficios.com> <20260817151646.152571-11-simon.marchi@efficios.com> <87bjb03dc5.fsf@redhat.com> Content-Language: fr From: Simon Marchi In-Reply-To: <87bjb03dc5.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YQBPR0101CA0307.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:6c::29) To YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:2c::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YQXPR01MB5418:EE_|YT3PR01MB10752:EE_ X-MS-Office365-Filtering-Correlation-Id: a24386d5-f4fa-4727-16aa-08defc854540 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|23010399003|1800799024|376014|6133799003|10067099003|56012099006|4143699003|3023799007|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: zEjF6mWaG/DhibPPLg2u5jy6VTFYSQ9Hy4tc7ufh0txDC18azKojOumX8J2i439BzjeRgyjaH27TC4N4CXeBPyvXzCyiwyscGZDoJWGXy8lntVhxRQkW++2WlWkDpjnx2TlLD9wUCXYTUgJ83v4K0llOy0q1xCRP6sWMyzATUQmATmbi9By+W0OtQhFbS2dF72/z+70fckuJchVlybDb/mqten8lPf2xOhVAwtuqj1VLR2CCa7TDxre/VIFfaUvuViT4hF6jWRdph3ZF+XZ1WsHjHr7ZEtKys2D4dXk713cTVt4pclLOZjH8dmficlNDET/AJDehSrJRnskwe+P6NypN8Gc/MRudWT1fNxJI41cNv14jzZ7JfzoM8p6/IlAGPWrFvtx3hiFcnHf6NbGdMHx9RxvVD3jl1NRZIHFdP6D8hetlWrN+QzT/ZtyxbuaHntwq4dXe/Rg20ay7ftZRTFicxf2/V0QyszVpQFZKWUk17jx7pgQWjj4RzHyWCIN7tZmpzMsU5YR13CGbW/BmvQepxIFig0y12QWeFwQ06lzVMtvyx+xdoAhchG44oafgtYG2UhcS9vUzfRdvODI07vmQ56m+9Q098X/qOYKBWxnGaNT3NBKNyTeDRbbq9vrgTxoQ1b6qXiTd/tZY3HPblxhvsSyyW5RAN0kG2UcN35U= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(366016)(23010399003)(1800799024)(376014)(6133799003)(10067099003)(56012099006)(4143699003)(3023799007)(18002099003)(22082099003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SmZHWU56U2dJM0ovU1Izdk1EOVA4WGZ3NWlDOUh6SnJVWTZnMU5OVHhja1dh?= =?utf-8?B?SklHNVBKMzBXWlJhOW9zRlVhRXhDb0ZCeFRYV0UrZDZudDduNlgyaVlDMkhH?= =?utf-8?B?aGhGYTBlcmNwVnNIL2tpNytYM1N5NTdpYUROV3pJQUR1NnYrMVF3SWp6SytS?= =?utf-8?B?R1g1eFYvbGpGZzFmRnYzOXFySVNSVUsyUHNuVzUvRVVvQWVjQytzc2lZcWw1?= =?utf-8?B?SHg5R1UrRWtVT3ZvMzAxbnRzaWZJRlB2azVTd2s3OHhRZ3FwRE5BNnlvUDBi?= =?utf-8?B?Q1E5VllWLzRacjNIZkdHZ3dkN0VYRVlGOS9acGJRRU16TlMzWE1CNnhIL1ZI?= =?utf-8?B?SjFkc21uZEUrR2NyZGlER1JYdFp1NGxEWHFhcU5UTmpqWm43aUhIR3ErZmdi?= =?utf-8?B?bUV0L1ppQVYxclU2a2pBWmhaOGJDV0NRSkRnUFFVR2lpVkh2RDZ6Q1oxaTNC?= =?utf-8?B?ejAzdUJnbWtOTFIzUjZqVkExK3UxQXZqRHpnZEczNnAwMXpta0prMmc2SW94?= =?utf-8?B?NGxSajNyZnBXM2JMUjFqU0hMZDNNRGNveUtPRnBJNTVGWXRoRzNRWkNuU0hN?= =?utf-8?B?ZW1wdmlUNGxuOUZYR1FmYWlpUTYxdzVpN1JCSGpHWTZDVjhKeURQNGVOR3hF?= =?utf-8?B?K3VKY1NIZzVqY3RZb084QWh4b0tpVHlTTFJvb1RDSmxKemp1K01kVHl1R1JI?= =?utf-8?B?ekdMTUQrdnZmNWtRRFFLbnFpblBFNm94K0ZyUzl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XBrMTVQYnBwOTVBOU5QNlFZbUZr?= =?utf-8?B?cE9JM3BmWGQ4VWhwOGdYQkRoYTJ6QXJsQ3NTZWVZNkdYM3lCaG0xTkc2U3lJ?= =?utf-8?B?WmxJQzBSMk13NVZObzZIZ2svL0QvUHpPT3A1MVR4U0NCMElhdDVmaHlSRWhE?= =?utf-8?B?a1RYL2NSVFYxUEFCd0g5M0loUnlQZ005RmdCZjZlODg2MmJhdW5mNlNTZ0Nx?= =?utf-8?B?dnBXN1VRUCtTQ2c2T29lYTBGNDkwd1pOVm4xazFxeUZOMkJUMG0yajZpQnpt?= =?utf-8?B?RUNCR3RvYmZId0QyZ3R4T294Q2p3RnR0TzJMUTJiUVplUThPSWZRcHg2K3ZV?= =?utf-8?B?RTZNTlpYUVdRamJ3N1dLT3o1NThRNUwxWDhwbnBwekFxT0xUQTNINHN5Mnow?= =?utf-8?B?a2h3OENTYTNzNE5VaU5CbVBNNDREb0hSQmFDbzVtMU9vQUMxb2FNdDM0QmZV?= =?utf-8?B?REdlY2RNRXlPejhrZXlPR0hqNjdzUGZlczE2MnRvQ2Nod0tEVG1wVWxsR1VF?= =?utf-8?B?S3ZmRi9HNGg2M1ZTYmJ6dkt4amkzTzdZVHpNbWZxekZLUFE1SHg4SUhQa0to?= =?utf-8?B?akN0MG84VjdFME5zV2NSWThRSVlsSWExbkw4Y0tidCtiMmpGeXp3bkxVZGhv?= =?utf-8?B?RnhWd3RVK1h1WDB1OGRIcCs3VkZKeDdwd2N2MmZ6ZjRGQWt4RDUvdz09?= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: a24386d5-f4fa-4727-16aa-08defc854540 X-MS-Exchange-CrossTenant-AuthSource: YQXPR01MB5418.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2026 17:30:45.7023 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U+N4qQ0iOZtPrwB1OsdEKyKqX+9AzyEbGelrZsvefpPyBnsTvYf57/gyI9HqLWUcNP21rVGcrrmHDFEOReAGww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: YT3PR01MB10752 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 8/17/26 12:45 PM, Andrew Burgess wrote: > Simon Marchi writes: > >> Add xstrcpy, a "safe" alternative to strcpy. It works like strcpy, but >> accepts the size of the destination buffer, and asserts that the string >> fits in it. >> >> Return the number of characters copied, so that it's possible to easily >> chain calls like this: >> >> p += xstrcpy (p, end - p, ",C"); > > Don't functions that take a buffer size usually include an 'n' in the > name. That seems to be true for libc, but also throughout GDB. Would > it not be a good idea to adopt that here too. > > This isn't exactly strncpy, but it seems similar. While strncpy can > result in a non-null terminated output string, this "xstrncpy" asserts > that the source fits into the output buffer without being truncated. > But otherwise, it's the same function I think? I hesitated about naming it strncpy. I decided against it because the new function doesn't behave exactly like strcnpy on one specific point: if the source is smaller than destination, strncpy fills the remainder of the destination buffer with zeroes. Not sure if that matters in practice, but it could be the source of a subtle bug if one blindly switches strncpy for xstrncpy. Both strcpy and strncpy return a pointer to the beginning of the destination buffer, which is different than my xstrcpy, which returns the number of bytes written. The latter seems more useful to me, as it makes it possible to easily chain the calls. It seems like xstrcpy is more like a wrapper for strlcpy, so we could always call it xstrlcpy. The only thing is that the argument order is not the same: int xstrcpy (char *dst, size_t size, const char *src); size_t strlcpy (char *dst, const char *src, size_t size); So if we named it xstrlcpy, I would want to match xstrlcpy's argument order, otherwise it's just confusing. Personally, I don't strlcpy's argument order as much, because `size` describes `dst`, so I like having it right next to it. But I could live with it. I just noticed that strcpy_s exists in C11, and it is in the same order as xstrcpy: errno_t strcpy_s (char* restrict dest, rsize_t destsz, const char* restrict src); It looks like we could use that, but we also want to return the number of bytes written, which this does not provide. I also considered accepting `dst` as a `gdb::array_view`, which would side-step the argument order problem, but the caller's are not really ready for that, so their would look look awkward. In any case, I still believe that the xstrcpy makes sense, because it is really like "strcpy, but safe". Given all this, what would be your choice? Simon