From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yQQAJHHDvmo1WCUAWB0awg (envelope-from ) for ; Thu, 01 Oct 2026 16:32:49 -0400 Received: by simark.ca (Postfix, from userid 112) id 900741E04F; Thu, 01 Oct 2026 16:32:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 166951E047 for ; Thu, 01 Oct 2026 16:32:49 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A246F4B9700B for ; Thu, 1 Oct 2026 20:32:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A246F4B9700B Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6F9604BB24E6 for ; Thu, 1 Oct 2026 20:31:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F9604BB24E6 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 6F9604BB24E6 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=1790886675; cv=none; b=P6I3s3eUh9tuIQ6IvCJZ9qeTckcYUuXSektNaFxkfDy1zvtWa6viTItwCvtaC3qlU+gO4WtoePR85pvnAMcpCaUTKauE4aN3/XeeG8uSFB+U37kj3aG5Jl9GhKQs7JLFyNwe+qlBAS6mF3tcYxaedUPlsB8I1sFGhZODfPYP4Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790886675; c=relaxed/simple; bh=WHqWSDsxOGDRtpDGpLNFW8idDuKyiutNItfIczsjuAQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=K/PMuOoU7pMpl6QwtH8QsPQY5amESKZoc5PWcaSdV4gVotZ63/7UI3EXcBYaAVW+j2K30hNj+yWVhGQ6q2XjOyK4piPa9+REfSWQyPD/hi2Phk8Qko/G/vbFTWcboyXeyR8Tzar0HFpFxxpN05awVNe4Fr0guNIlXRDmVazFxvo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F9604BB24E6 Received: by simark.ca (Postfix) id A617B1E091; Thu, 01 Oct 2026 16:31:12 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 5/7] gdb: use std::string for f-exp-parser.c's tempbuf Date: Thu, 1 Oct 2026 16:30:03 -0400 Message-ID: <20261001203105.1379971-6-simon.marchi@efficios.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001203105.1379971-1-simon.marchi@efficios.com> References: <20261001203105.1379971-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 Replace the tempbuf / tempbufsize / tempbufindex trio, the GROWBY_MIN_SIZE and CHECKBUF macros and the growbuf_by_size function with a single std::string. match_string_literal is the only user of that buffer. std::string null-terminates, so the explicit terminator write goes away. Change-Id: Ia978b6340d59e99b5c8f4dd0ea904471c66f37f6 --- gdb/f-exp-parser.c | 55 +++++++++++----------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/gdb/f-exp-parser.c b/gdb/f-exp-parser.c index 9e0c7aa6650c..010561d83ba5 100644 --- a/gdb/f-exp-parser.c +++ b/gdb/f-exp-parser.c @@ -25,7 +25,7 @@ #include "language.h" #include "parser-defs.h" #include "value.h" -#include +#include /* The entry point of the bison/yacc-generated parser, defined in f-exp-parser-gen.c. Bison produces a declaration for f_yyparse in @@ -574,40 +574,6 @@ static const f_token f_keywords[] = { "precision", PRECISION, OP_NULL, true }, }; -/* Implementation of a dynamically expandable buffer for processing input - characters acquired through lexptr and building a value to return in - yylval. Ripped off from ch-exp.y */ - -static char *tempbuf; /* Current buffer contents */ -static int tempbufsize; /* Size of allocated buffer */ -static int tempbufindex; /* Current index into buffer */ - -#define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */ - -#define CHECKBUF(size) \ - do { \ - if (tempbufindex + (size) >= tempbufsize) \ - { \ - growbuf_by_size (size); \ - } \ - } while (0); - -/* Grow the static temp buffer if necessary, including allocating the - first one on demand. */ - -static void -growbuf_by_size (int count) -{ - int growby; - - growby = std::max (count, GROWBY_MIN_SIZE); - tempbufsize += growby; - if (tempbuf == NULL) - tempbuf = (char *) xmalloc (tempbufsize); - else - tempbuf = (char *) xrealloc (tempbuf, tempbufsize); -} - /* Blatantly ripped off from ch-exp.y. This routine recognizes F77 string-literals. @@ -622,9 +588,13 @@ match_string_literal (void) { const char *tokptr = pstate->lexptr; - for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++) + /* Buffer used to build and hold the string value returned in f_yylval. Its + contents are only valid until the next call. */ + static std::string tempbuf; + + tempbuf.clear (); + for (tokptr++; *tokptr != '\0'; tokptr++) { - CHECKBUF (1); if (*tokptr == *pstate->lexptr) { if (*(tokptr + 1) == *pstate->lexptr) @@ -632,16 +602,17 @@ match_string_literal (void) else break; } - tempbuf[tempbufindex++] = *tokptr; + + tempbuf += *tokptr; } + if (*tokptr == '\0' /* no terminator */ - || tempbufindex == 0) /* no string */ + || tempbuf.empty ()) /* no string */ return 0; else { - tempbuf[tempbufindex] = '\0'; - f_yylval.sval.ptr = tempbuf; - f_yylval.sval.length = tempbufindex; + f_yylval.sval.ptr = tempbuf.c_str (); + f_yylval.sval.length = tempbuf.size (); pstate->lexptr = ++tokptr; return STRING_LITERAL; } -- 2.55.0