Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb: remove uses of alloca in gdbtypes.c
Date: Thu, 31 Aug 2023 15:56:10 -0400	[thread overview]
Message-ID: <20230831195611.1286355-1-simon.marchi@efficios.com> (raw)

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace two uses of alloca with std::string.

Change-Id: I970ae3f450da407494d95668a57bba8796d6292b
---
 gdb/gdbtypes.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 59ddd75ab798..5e15ec64c41c 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1670,11 +1670,12 @@ struct type *
 lookup_unsigned_typename (const struct language_defn *language,
 			  const char *name)
 {
-  char *uns = (char *) alloca (strlen (name) + 10);
+  std::string uns;
+  uns.reserve (strlen (name) + strlen ("unsigned "));
+  uns = "unsigned ";
+  uns += name;
 
-  strcpy (uns, "unsigned ");
-  strcpy (uns + 9, name);
-  return lookup_typename (language, uns, NULL, 0);
+  return lookup_typename (language, uns.c_str (), NULL, 0);
 }
 
 struct type *
@@ -1760,16 +1761,14 @@ struct type *
 lookup_template_type (const char *name, struct type *type, 
 		      const struct block *block)
 {
-  struct symbol *sym;
-  char *nam = (char *) 
-    alloca (strlen (name) + strlen (type->name ()) + 4);
-
-  strcpy (nam, name);
-  strcat (nam, "<");
-  strcat (nam, type->name ());
-  strcat (nam, " >");	/* FIXME, extra space still introduced in gcc?  */
+  std::string nam;
+  nam.reserve (strlen (name) + strlen (type->name ()) + strlen ("< >"));
+  nam = name;
+  nam += "<";
+  nam += type->name ();
+  nam += " >"; /* FIXME, extra space still introduced in gcc?  */
 
-  sym = lookup_symbol (nam, block, VAR_DOMAIN, 0).symbol;
+  symbol *sym = lookup_symbol (nam.c_str (), block, VAR_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {

base-commit: 911e1e795e2496e1a5315601ab89e56afcd10fb0
-- 
2.42.0


             reply	other threads:[~2023-08-31 19:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 19:56 Simon Marchi via Gdb-patches [this message]
2023-08-31 22:09 ` Kevin Buettner via Gdb-patches
2023-09-01  1:29   ` Simon Marchi via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230831195611.1286355-1-simon.marchi@efficios.com \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox