From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id BDCD33858C2C; Fri, 22 Apr 2022 15:22:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDCD33858C2C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use std::string in coff-pe-read.c X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: fa265c9bef46fc2211f8dccbc9d9b432778087be X-Git-Newrev: 0f34437ba0f5acab1fcb05630d88057402abbfeb Message-Id: <20220422152231.BDCD33858C2C@sourceware.org> Date: Fri, 22 Apr 2022 15:22:31 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 15:22:31 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0f34437ba0f5= acab1fcb05630d88057402abbfeb commit 0f34437ba0f5acab1fcb05630d88057402abbfeb Author: Tom Tromey Date: Tue Apr 19 07:33:09 2022 -0600 Use std::string in coff-pe-read.c =20 coff-pe-read.c uses xsnprintf and alloca, but using std::string is better, and just as easy. In general I think alloca is something to be avoided, and unbounded uses especially so. Diff: --- gdb/coff-pe-read.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index ae4ca5435b6..5bf0e2dc7f0 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -178,16 +178,13 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, struct bound_minimal_symbol msymbol; enum minimal_symbol_type msymtype; int forward_dll_name_len =3D strlen (forward_dll_name); - int forward_func_name_len =3D strlen (forward_func_name); - int forward_len =3D forward_dll_name_len + forward_func_name_len + 2; - char *forward_qualified_name =3D (char *) alloca (forward_len); short section; =20 - xsnprintf (forward_qualified_name, forward_len, "%s!%s", forward_dll_nam= e, - forward_func_name); + std::string forward_qualified_name =3D string_printf ("%s!%s", + forward_dll_name, + forward_func_name); =20 - - msymbol =3D lookup_bound_minimal_symbol (forward_qualified_name); + msymbol =3D lookup_bound_minimal_symbol (forward_qualified_name.c_str ()= ); =20 if (!msymbol.minsym) { @@ -195,7 +192,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, =20 for (i =3D 0; i < forward_dll_name_len; i++) forward_qualified_name[i] =3D tolower (forward_qualified_name[i]); - msymbol =3D lookup_bound_minimal_symbol (forward_qualified_name); + msymbol =3D lookup_bound_minimal_symbol (forward_qualified_name.c_st= r ()); } =20 if (!msymbol.minsym)