This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[review v2] Only make a nullterminated string if we need to
- From: "Christian Biesinger (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: Christian Biesinger <cbiesinger at google dot com>, Luis Machado <luis dot machado at linaro dot org>, gdb-patches at sourceware dot org
- Cc: Tom Tromey <tromey at sourceware dot org>
- Date: Fri, 25 Oct 2019 16:02:27 -0400
- Subject: [review v2] Only make a nullterminated string if we need to
- Auto-submitted: auto-generated
- References: <gerrit.1571783424000.I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2@gnutoolchain-gerrit.osci.io>
- Reply-to: cbiesinger at google dot com, tromey at sourceware dot org, luis dot machado at linaro dot org, cbiesinger at google dot com, gdb-patches at sourceware dot org
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/222
......................................................................
Only make a nullterminated string if we need to
As of 7bb43059820c5febb4509b15202a93efde442bc6, we no longer need
a nullterminated linkage_name to look up the entry in the hash table.
So this patch makes it so we only make the copy if the entry was
not found.
gdb/ChangeLog:
2019-10-22 Christian Biesinger <cbiesinger@google.com>
* symtab.c (symbol_set_names): Only make a nullterminated copy of
linkage_name if the entry was not found and we need to demangle.
Change-Id: I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2
---
M gdb/symtab.c
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 79c5fde..65d6311 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -832,8 +832,6 @@
struct objfile_per_bfd_storage *per_bfd)
{
struct demangled_name_entry **slot;
- /* A 0-terminated copy of the linkage name. */
- const char *linkage_name_copy;
if (gsymbol->language == language_ada)
{
@@ -858,20 +856,7 @@
if (per_bfd->demangled_names_hash == NULL)
create_demangled_names_hash (per_bfd);
- if (linkage_name[len] != '\0')
- {
- char *alloc_name;
-
- alloc_name = (char *) alloca (len + 1);
- memcpy (alloc_name, linkage_name, len);
- alloc_name[len] = '\0';
-
- linkage_name_copy = alloc_name;
- }
- else
- linkage_name_copy = linkage_name;
-
- struct demangled_name_entry entry (gdb::string_view (linkage_name_copy, len));
+ struct demangled_name_entry entry (gdb::string_view (linkage_name, len));
slot = ((struct demangled_name_entry **)
htab_find_slot (per_bfd->demangled_names_hash.get (),
&entry, INSERT));
@@ -882,6 +867,21 @@
This happens to, e.g., main.init (__go_init_main). Cope. */
|| (gsymbol->language == language_go && (*slot)->demangled == nullptr))
{
+ /* A 0-terminated copy of the linkage name. */
+ const char *linkage_name_copy;
+ if (linkage_name[len] != '\0')
+ {
+ char *alloc_name;
+
+ alloc_name = (char *) alloca (len + 1);
+ memcpy (alloc_name, linkage_name, len);
+ alloc_name[len] = '\0';
+
+ linkage_name_copy = alloc_name;
+ }
+ else
+ linkage_name_copy = linkage_name;
+
gdb::unique_xmalloc_ptr<char> demangled_name_ptr
(symbol_find_demangled_name (gsymbol, linkage_name_copy));
@@ -912,7 +912,8 @@
obstack_alloc (&per_bfd->storage_obstack,
sizeof (demangled_name_entry) + len + 1));
char *mangled_ptr = reinterpret_cast<char *> (*slot + 1);
- strcpy (mangled_ptr, linkage_name_copy);
+ memcpy (mangled_ptr, linkage_name, len);
+ mangled_ptr [len] = '\0';
new (*slot) demangled_name_entry
(gdb::string_view (mangled_ptr, len));
}
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2
Gerrit-Change-Number: 222
Gerrit-PatchSet: 2
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Luis Machado <luis.machado@linaro.org>
Gerrit-CC: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newpatchset