From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UTpUHJaNcmmnUBAAWB0awg (envelope-from ) for ; Thu, 22 Jan 2026 15:50:30 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=AXO2tpyZ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 61A9F1E093; Thu, 22 Jan 2026 15:50:30 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 CE5001E0AD for ; Thu, 22 Jan 2026 15:50:27 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 493614BC89A8 for ; Thu, 22 Jan 2026 20:50:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 493614BC89A8 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=AXO2tpyZ Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by sourceware.org (Postfix) with ESMTPS id CEFDA4BA900C for ; Thu, 22 Jan 2026 20:49:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEFDA4BA900C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CEFDA4BA900C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769114955; cv=none; b=w1hK0sCI6ypByPNVmUNG5eYvsdr2rDCj+gXisRvaZmKJpPfprcV1CiRdHOFYUFSR0LiocpCprtmOJEPdx5E1wmBbHKleiO1AoyRtcP9g7ZtfG3Pt/AqnN/awKJCFiWlH8DKuEZU9lC7e7MqYpgl7SlVuMhjC3K5FfzqiN2Cq/6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769114955; c=relaxed/simple; bh=NsqUYcx4Ft7p5kuPtP0Rtdp5mvcmHdK97Il7RiAWToM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=OCmG9yvXhLytNQUs9LRiOLq9vhEpmrmRqX+Qy1qYXc9EqK/poWw63MaD48El1f3bFuD+caYq3tl1n2w5x2YMrurA0LCuEo/54EZdeD1bHpo50rwOHJ26WEqvytgssqOsrIY8GtvKgG5aMJ8SfUTG2GMGCrx2r7Ndvzq7ea1ZJLw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEFDA4BA900C Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-408199852c5so636930fac.0 for ; Thu, 22 Jan 2026 12:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1769114955; x=1769719755; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=v0MTUZQZgaz4CbFfEMd2v5ltY2fognbrdDOq7gt6i7M=; b=AXO2tpyZq72tWVuvgDhQGCJLtLDvFiWAHFc88nQ5MQnVP9UwEyR6X7Lmvw1n1dG9yY IwXPd4Bv0a8g5miC4XBzhMoyVKVTbhypAmWIYaXvuQmnwrNZSYFxI7+9+2yg2e6oRbZw LI+zEYF090GyoejHS4HcpjsQxe9VSKOdG8EJrk3G6kfpuYHzkOSoKEA0QXZee3w84Kuq CZlb4u9QAUOFbBZtGiHWby+haoAnzLBA+3os9kCamVr7Fn/pTVpkRVo3/hYugW/PsHdl uaY3p1VXE3GWu0tBF73f/qHYh07IOPUTMZQgbvUkfqQXx9hjmcmAsFlbV0coQnY/0gGa EaFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769114955; x=1769719755; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=v0MTUZQZgaz4CbFfEMd2v5ltY2fognbrdDOq7gt6i7M=; b=vxH82Rso5OReIRdTFbns3OLCzmsSxunFs4xZOnCTqGEUpUafD8aPFMfDCmSQG/5W+V Azfy/D8Qg9G2Tb+RUn0EXr3QXyTvGuDa1+fsKtPPlx56Ee5iq7s4JGFa6/tNz8uoiDiU ab8/1TN9A2Sf9CDt8oKL7nga/2ZpZkZ7uR6ZQR9njPhQmYINkYDL8cMeWX/T8hzuxD2O l3Q5JyU9zxQ7NhsDTyT38SrYxErPh7nJ/Xe9Jtydi4Rk/JgscB1/rDU/aTl9StzM6Rlx +pDFTTCCJg0WnLNPRVkgwC6pNa43kQi0a1r9l2/U1YB4GzbvNtOOox4JF5D/IJJdWKni GpEw== X-Gm-Message-State: AOJu0Yz0MXMtuExpfs8510LSsgDZsGeNMJQ/rdNqtWpProJE78hV63Iy jJJj/YjKk5weuWJBdjSu4w2tEXdfB+RKGHrzvtzWYHbUC1M5VSTcb+AwkL6ANA0BAPxl9PRyQy0 4fhE= X-Gm-Gg: AZuq6aKmmhvyKqdXhqdPjv22/RQVymUCnXbAu+FAfVsCF+ezURzRUB1xwi0rRqR98ZZ pcCIFLsfEUj14SOvjtyLTGQdj+tXKX4Snxb7gHFUvrpy9OuQUq0WIIvCgg/wDQwnZsWcmBXhBmh 94C+jwYTcOvS1aAoPiDzCoeU8l8PckNxQ/knk79eMSkBhXrQzM0O5+EB5eCnEnZd7xQU3p5g5Lh tNSHIpftblD0I9SzEZ5TG0Ds7jl5pVZKR+jGv7gWnvU5sdc1kB+MfKbcMZ6xmqPNENYEE5F12D+ PdBIEPYn+/Jgiejgi1SOjEwrsfoYYy1w2iuy7jWF6x0GEj/OMVHlqc2GIsMt8uSxylDU97Q2HGw uEQKl24Oi0gz/56r4KAdJfxYJOLib3AoekkFsIyoYy1EUf8wXWyE0z25+is848PfujvvkmIXqUa AyLabeqyJiW5TIZSDJiGfwfqM5jDa2ixrwmx1kei/i/BMaYIuQOiOW X-Received: by 2002:a05:6870:71c3:b0:3f5:ba8f:5b19 with SMTP id 586e51a60fabf-408aac7dc77mr697287fac.0.1769114955167; Thu, 22 Jan 2026 12:49:15 -0800 (PST) Received: from [192.168.0.26] (97-122-114-32.hlrn.qwest.net. [97.122.114.32]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-408afba74bfsm176755fac.13.2026.01.22.12.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 12:49:14 -0800 (PST) From: Tom Tromey Date: Thu, 22 Jan 2026 13:49:13 -0700 Subject: [PATCH 3/3] Remove alloca from lookup_cmd MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260122-command-no-alloca-v1-3-402aa429bbbf@adacore.com> References: <20260122-command-no-alloca-v1-0-402aa429bbbf@adacore.com> In-Reply-To: <20260122-command-no-alloca-v1-0-402aa429bbbf@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 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 lookup_cmd uses alloca to make a copy of a string, just for an error message. However, it's just as easy to use "%.*s" (already used once in undef_cmd_error) and to pass in a string_view, avoiding the need for an alloca and a copy. --- gdb/cli/cli-decode.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index f581f128a34..285f5f1f0c4 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -27,8 +27,6 @@ /* Prototypes for local functions. */ -static void undef_cmd_error (const char *, const char *); - static cmd_list_element::aliases_list_type delete_cmd (const char *name, cmd_list_element **list, cmd_list_element **prehook, cmd_list_element **prehookee, cmd_list_element **posthook, @@ -2369,11 +2367,11 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, /* All this hair to move the space to the front of cmdtype */ static void -undef_cmd_error (const char *cmdtype, const char *q) +undef_cmd_error (const char *cmdtype, std::string_view q) { - error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."), + error (_("Undefined %scommand: \"%.*s\". Try \"help%s%.*s\"."), cmdtype, - q, + (int) q.size (), q.data (), *cmdtype ? " " : "", (int) strlen (cmdtype) - 1, cmdtype); @@ -2419,13 +2417,8 @@ lookup_cmd (const char **line, struct cmd_list_element *list, { if (!allow_unknown) { - char *q; int len = find_command_name_length (*line); - - q = (char *) alloca (len + 1); - strncpy (q, *line, len); - q[len] = '\0'; - undef_cmd_error (cmdtype, q); + undef_cmd_error (cmdtype, std::string_view (*line, len)); } else return 0; @@ -2491,7 +2484,7 @@ lookup_cmd (const char **line, struct cmd_list_element *list, *line = skip_spaces (*line); if (c->is_prefix () && **line && !c->allow_unknown) - undef_cmd_error (c->prefixname ().c_str (), *line); + undef_cmd_error (c->prefixname ().c_str (), std::string_view (*line)); /* Seems to be what he wants. Return it. */ return c; -- 2.52.0