public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix symtab.c build on 32 bit targets
@ 2022-11-17 18:32 Simon Marchi
  2022-11-18 15:37 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-11-17 18:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: ro, Simon Marchi

When building on Ubuntu 22.04, gcc 12, x86-64 with -m32 and -O2, I get:

      CXX    symtab.o
    /home/smarchi/src/binutils-gdb/gdb/symtab.c: In member function ‘std::vector<symbol_search> global_symbol_searcher::search() const’:
    /home/smarchi/src/binutils-gdb/gdb/symtab.c:4961:44: error: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
     4961 |               sprintf (tmp, "operator%.*s%s", fix, " ", opname);
          |                                            ^
    In file included from /usr/include/stdio.h:894,
                     from ../gnulib/import/stdio.h:43,
                     from /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:86,
                     from /home/smarchi/src/binutils-gdb/gdb/defs.h:28,
                     from /home/smarchi/src/binutils-gdb/gdb/symtab.c:20:
    In function ‘int sprintf(char*, const char*, ...)’,
        inlined from ‘std::vector<symbol_search> global_symbol_searcher::search() const’ at /home/smarchi/src/binutils-gdb/gdb/symtab.c:4961:16:
    /usr/include/i386-linux-gnu/bits/stdio2.h:38:34: note: ‘__builtin___sprintf_chk’ output between 9 and 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 ());
          |                                   ~~~~~~~~~~~~~~~~~

PR 29798 shows a similar error message but on Solaris.

Work around that by using string_printf.  It is a good thing to get rid
of the alloca anyway.

Change-Id: Ifbac11fee3062ad7f134d596b4e2229dc5d166f9
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29798
---
 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 != NULL)
     {
       const char *symbol_name_regexp = m_symbol_name_regexp;
+      std::string symbol_name_regexp_holder;
 
       /* 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 >= 0)
 	    {
-	      char *tmp = (char *) alloca (8 + fix + strlen (opname) + 1);
-
-	      sprintf (tmp, "operator%.*s%s", fix, " ", opname);
-	      symbol_name_regexp = tmp;
+	      symbol_name_regexp_holder
+		= string_printf ("operator%.*s%s", fix, " ", opname);
+	      symbol_name_regexp = symbol_name_regexp_holder.c_str ();
 	    }
 	}
 
-- 
2.37.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: fix symtab.c build on 32 bit targets
  2022-11-17 18:32 [PATCH] gdb: fix symtab.c build on 32 bit targets Simon Marchi
@ 2022-11-18 15:37 ` Tom Tromey
  2022-11-18 15:47   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-11-18 15:37 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi, ro

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> PR 29798 shows a similar error message but on Solaris.

It should say "PR build/29798" here, so the commit script can pick it
up.

Simon> Work around that by using string_printf.  It is a good thing to get rid
Simon> of the alloca anyway.

Indeed.  IMO alloca should be poisoned.
The patch looks good to me.

Simon> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29798

... we should teach that commit script to pick this up.
I don't know how to access it, though.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: fix symtab.c build on 32 bit targets
  2022-11-18 15:37 ` Tom Tromey
@ 2022-11-18 15:47   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2022-11-18 15:47 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi, ro



On 11/18/22 10:37, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> PR 29798 shows a similar error message but on Solaris.
> 
> It should say "PR build/29798" here, so the commit script can pick it
> up.

Fixed.

> 
> Simon> Work around that by using string_printf.  It is a good thing to get rid
> Simon> of the alloca anyway.
> 
> Indeed.  IMO alloca should be poisoned.
> The patch looks good to me.

Thanks, will push.

> 
> Simon> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29798
> 
> ... we should teach that commit script to pick this up.
> I don't know how to access it, though.

I will ask Joel.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-18 15:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 18:32 [PATCH] gdb: fix symtab.c build on 32 bit targets Simon Marchi
2022-11-18 15:37 ` Tom Tromey
2022-11-18 15:47   ` Simon Marchi

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).