From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 0F9C93853D4D; Fri, 18 Nov 2022 15:48:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F9C93853D4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668786503; bh=iI2yA4WumhdJar7tPyX5gS+hgpmPFSzlzI6cfcH7EBg=; h=From:To:Subject:Date:From; b=MwFGiXPob72YNDSOhusLO3m8rlkt56FsF5J2s0fNJwU8G/bxnaf3K2AeGHoXrDGPb 9BoJIaRDQbwqgfrI6dH1Z8Sbk11xuAViQjQb8EYQY+0jfmw1ndSeZLeOUJG8AOX299 itT8puXCsyrUJXrVF+dDCCLNLbK5YLcNTFqq4oAE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: fix symtab.c build on 32 bit targets X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: f9f88aede3bb84efd088a59a5f6bccb3a6bb6516 X-Git-Newrev: 9c48a8e6f43965b8d530159e5dbb2fc9d6083646 Message-Id: <20221118154823.0F9C93853D4D@sourceware.org> Date: Fri, 18 Nov 2022 15:48:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9c48a8e6f439= 65b8d530159e5dbb2fc9d6083646 commit 9c48a8e6f43965b8d530159e5dbb2fc9d6083646 Author: Simon Marchi Date: Fri Nov 18 10:48:03 2022 -0500 gdb: fix symtab.c build on 32 bit targets =20 When building on Ubuntu 22.04, gcc 12, x86-64 with -m32 and -O2, I get: =20 CXX symtab.o /home/smarchi/src/binutils-gdb/gdb/symtab.c: In member function =C3= =A2=E2=82=AC=CB=9Cstd::vector global_symbol_searcher::search= () const=C3=A2=E2=82=AC=E2=84=A2: /home/smarchi/src/binutils-gdb/gdb/symtab.c:4961:44: error: =C3=A2= =E2=82=AC=CB=9C__builtin___sprintf_chk=C3=A2=E2=82=AC=E2=84=A2 may write a = terminating nul past the end of the destination [-Werror=3Dformat-overflow= =3D] 4961 | sprintf (tmp, "operator%.*s%s", fix, " ", opn= ame); | ^ In file included from /usr/include/stdio.h:894, from ../gnulib/import/stdio.h:43, from /home/smarchi/src/binutils-gdb/gdb/../gdbsupp= ort/common-defs.h:86, from /home/smarchi/src/binutils-gdb/gdb/defs.h:28, from /home/smarchi/src/binutils-gdb/gdb/symtab.c:2= 0: In function =C3=A2=E2=82=AC=CB=9Cint sprintf(char*, const char*, ..= .)=C3=A2=E2=82=AC=E2=84=A2, inlined from =C3=A2=E2=82=AC=CB=9Cstd::vector gl= obal_symbol_searcher::search() const=C3=A2=E2=82=AC=E2=84=A2 at /home/smarc= hi/src/binutils-gdb/gdb/symtab.c:4961:16: /usr/include/i386-linux-gnu/bits/stdio2.h:38:34: note: =C3=A2=E2=82= =AC=CB=9C__builtin___sprintf_chk=C3=A2=E2=82=AC=E2=84=A2 output between 9 a= nd 2147483648 bytes into a destination of size 2147483647 38 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL = - 1, | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ 39 | __glibc_objsize (__s), __= fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ 40 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ =20 PR build/29798 shows a similar error message but on Solaris. =20 Work around that by using string_printf. It is a good thing to get rid of the alloca anyway. =20 Change-Id: Ifbac11fee3062ad7f134d596b4e2229dc5d166f9 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29798 Diff: --- gdb/symtab.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index ff8d24a5614..0d342f765f2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4928,6 +4928,7 @@ global_symbol_searcher::search () const if (m_symbol_name_regexp !=3D NULL) { const char *symbol_name_regexp =3D m_symbol_name_regexp; + std::string symbol_name_regexp_holder; =20 /* Make sure spacing is right for C++ operators. This is just a courtesy to make the matching less sensitive @@ -4956,10 +4957,9 @@ global_symbol_searcher::search () const /* If wrong number of spaces, fix it. */ if (fix >=3D 0) { - char *tmp =3D (char *) alloca (8 + fix + strlen (opname) + 1); - - sprintf (tmp, "operator%.*s%s", fix, " ", opname); - symbol_name_regexp =3D tmp; + symbol_name_regexp_holder + =3D string_printf ("operator%.*s%s", fix, " ", opname); + symbol_name_regexp =3D symbol_name_regexp_holder.c_str (); } }