From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZIIuOP8lg2qsLC0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 11:17:19 -0400 Received: by simark.ca (Postfix, from userid 112) id C6E941E033; Mon, 17 Aug 2026 11:17:19 -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.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 4C6F01E033 for ; Mon, 17 Aug 2026 11:17:19 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2CF614BA7998 for ; Mon, 17 Aug 2026 15:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CF614BA7998 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9C5784BA23E0; Mon, 17 Aug 2026 15:16:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C5784BA23E0 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C5784BA23E0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786979812; cv=none; b=OHnjgyAIsFHyKhpPGzqZ4J2+0ULxayB6Tcl9pUmBAPpGFRPDegGCiKdMUZC+1GnTiEyTT8k99/oOCqT8LECRQYNEgEaOGQ40HMZCSiES73aqNlQv/Id26okDtK1/bREdDnmYX8sLHpGinHdaY9d4jdwz3fnCedYqYd9WMJR1h4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786979812; c=relaxed/simple; bh=saJOl6jldeJgTFXVZ02MdCreFSBLMeWZuJX/MuA8eSI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EQXHDO5pzcQAOdu+Km1HZYNQUA6wEMsziVgPDiYwW8rOzU8VB+9ZNq9p/in9+D6Vqy1a4RwQCXf3JiXMS0izU9OHhB0bu0c5HH+UHVHpmtluj4lwjES7tx/k1qVyA2wUBiidMUZntkoCTbHvL5MbTDL2az2dimdCgR6R3HavKBg= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C5784BA23E0 Received: by simark.ca (Postfix) id 608251E09E; Mon, 17 Aug 2026 11:16:51 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org, binutils@sourceware.org Cc: Simon Marchi Subject: [PATCH 01/13] gdbsupport: remove uses of vsprintf Date: Mon, 17 Aug 2026 11:16:06 -0400 Message-ID: <20260817151646.152571-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817151646.152571-1-simon.marchi@efficios.com> References: <20260817151646.152571-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 When building on macOS, I get: CXX common-utils.o /Users/smarchi/src/binutils-gdb/gdbsupport/common-utils.cc:106:3: error: 'vsprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use vsnprintf(3) instead. [-Werror,-Wdeprecated-declarations] 106 | vsprintf (&str[0], fmt, vp); | ^ /Users/smarchi/src/binutils-gdb/gdbsupport/common-utils.cc:128:3: error: 'vsprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use vsnprintf(3) instead. [-Werror,-Wdeprecated-declarations] 128 | vsprintf (&str[0], fmt, args); | ^ /Users/smarchi/src/binutils-gdb/gdbsupport/common-utils.cc:166:3: error: 'vsprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use vsnprintf(3) instead. [-Werror,-Wdeprecated-declarations] 166 | vsprintf (&str[curr_size], fmt, args); | ^ We know that those calls should be safe because we computed the size that fmt+args take just before, and allocated that many bytes. But I also don't see a real downside in switching those calls to use vsnprintf and double check that everything went right. Change the type of the existing "size" variable in "string_vprintf" to "int", since that's what vsnprintf returns. Change-Id: I589d9a170fdd15cc31b44b76689c6d8c324e340a --- gdbsupport/common-utils.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc index 3ae3afcc380b..f31699be13a1 100644 --- a/gdbsupport/common-utils.cc +++ b/gdbsupport/common-utils.cc @@ -92,10 +92,9 @@ std::string string_printf (const char* fmt, ...) { va_list vp; - int size; va_start (vp, fmt); - size = vsnprintf (NULL, 0, fmt, vp); + int size = vsnprintf (NULL, 0, fmt, vp); va_end (vp); std::string str (size, '\0'); @@ -103,7 +102,8 @@ string_printf (const char* fmt, ...) /* C++11 and later guarantee std::string uses contiguous memory and always includes the terminating '\0'. */ va_start (vp, fmt); - vsprintf (&str[0], fmt, vp); + int ret = vsnprintf (&str[0], size + 1, fmt, vp); + gdb_assert (ret == size); va_end (vp); return str; @@ -115,17 +115,17 @@ std::string string_vprintf (const char* fmt, va_list args) { va_list vp; - size_t size; va_copy (vp, args); - size = vsnprintf (NULL, 0, fmt, vp); + int size = vsnprintf (NULL, 0, fmt, vp); va_end (vp); std::string str (size, '\0'); /* C++11 and later guarantee std::string uses contiguous memory and always includes the terminating '\0'. */ - vsprintf (&str[0], fmt, args); + int ret = vsnprintf (&str[0], size + 1, fmt, args); + gdb_assert (ret == size); return str; } @@ -152,10 +152,9 @@ std::string & string_vappendf (std::string &str, const char *fmt, va_list args) { va_list vp; - int grow_size; va_copy (vp, args); - grow_size = vsnprintf (NULL, 0, fmt, vp); + int grow_size = vsnprintf (NULL, 0, fmt, vp); va_end (vp); size_t curr_size = str.size (); @@ -163,7 +162,8 @@ string_vappendf (std::string &str, const char *fmt, va_list args) /* C++11 and later guarantee std::string uses contiguous memory and always includes the terminating '\0'. */ - vsprintf (&str[curr_size], fmt, args); + int ret = vsnprintf (&str[curr_size], grow_size + 1, fmt, args); + gdb_assert (ret == grow_size); return str; } -- 2.55.0