public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] More const use and alloca avoidance in coff-pe-read.c Date: Fri, 22 Apr 2022 15:22:36 +0000 (GMT) [thread overview] Message-ID: <20220422152236.CCB4D3857C4E@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8095d37f71c20dd9e6cb90d4f42fb868867263ed commit 8095d37f71c20dd9e6cb90d4f42fb868867263ed Author: Tom Tromey <tromey@adacore.com> Date: Tue Apr 19 07:41:44 2022 -0600 More const use and alloca avoidance in coff-pe-read.c This changes another function in coff-pe-read.c to use 'const' more, and to avoid the use of alloca by instead using std::string. Diff: --- gdb/coff-pe-read.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index 5bf0e2dc7f0..d533a96ef6d 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -525,20 +525,20 @@ read_pe_exported_syms (minimal_symbol_reader &reader, /* First handle forward cases. */ if (func_rva >= export_rva && func_rva < export_rva + export_size) { - char *forward_name = (char *) (erva + func_rva); - char *funcname = (char *) (erva + name_rva); - char *forward_dll_name = forward_name; - char *forward_func_name = forward_name; - char *sep = strrchr (forward_name, '.'); - - if (sep) + const char *forward_name = (const char *) (erva + func_rva); + const char *funcname = (const char *) (erva + name_rva); + const char *forward_dll_name = forward_name; + const char *forward_func_name = forward_name; + const char *sep = strrchr (forward_name, '.'); + + std::string name_storage; + if (sep != nullptr) { int len = (int) (sep - forward_name); - forward_dll_name = (char *) alloca (len + 1); - strncpy (forward_dll_name, forward_name, len); - forward_dll_name[len] = '\0'; - forward_func_name = ++sep; + name_storage = std::string (forward_name, len); + forward_dll_name = name_storage.c_str (); + forward_func_name = sep + 1; } if (add_pe_forwarded_sym (reader, funcname, forward_dll_name, forward_func_name, ordinal, @@ -552,7 +552,7 @@ read_pe_exported_syms (minimal_symbol_reader &reader, if ((func_rva >= section_data[sectix].rva_start) && (func_rva < section_data[sectix].rva_end)) { - char *sym_name = (char *) (erva + name_rva); + const char *sym_name = (const char *) (erva + name_rva); section_found = 1; add_pe_exported_sym (reader, sym_name, func_rva, ordinal, @@ -563,7 +563,7 @@ read_pe_exported_syms (minimal_symbol_reader &reader, } if (!section_found) { - char *funcname = (char *) (erva + name_rva); + const char *funcname = (const char *) (erva + name_rva); if (name_rva == 0) {
reply other threads:[~2022-04-22 15:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220422152236.CCB4D3857C4E@sourceware.org \ --to=tromey@sourceware.org \ --cc=gdb-cvs@sourceware.org \ /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: linkBe 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; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).