Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>,
	       Svante Signell <svante.signell@gmail.com>,
	gdb-patches@sourceware.org
Subject: Re: Small patch to enable build of gdb-7.6 for GNU/Hurd
Date: Fri, 24 May 2013 08:53:00 -0000	[thread overview]
Message-ID: <519F2A7A.4050002@redhat.com> (raw)
In-Reply-To: <20130524042734.GG4017@adacore.com>

On 05/24/2013 05:27 AM, Joel Brobecker wrote:
> On Thu, May 23, 2013 at 11:59:46PM -0300, Sergio Durigan Junior wrote:
>> Thanks for your patch, Svante.
>>
>> On Thursday, May 23 2013, Svante Signell wrote:
>>
>>> --- a/gdb/nto-tdep.c	2013-05-23 14:28:24.000000000 +0000
>>> +++ b/gdb/nto-tdep.c	2013-05-23 15:01:24.000000000 +0000
>>> @@ -147,9 +147,11 @@ nto_find_and_open_solib (char *solib, un
>>>  void
>>>  nto_init_solib_absolute_prefix (void)
>>>  {
>>> -  char buf[PATH_MAX * 2], arch_path[PATH_MAX];
>>> +  char *buf, *arch_path;
>>>    char *nto_root, *endian;
>>>    const char *arch;
>>> +  int arch_len, len;
>>> +#define FMT "set solib-absolute-prefix %s"
>>>  
>>>    nto_root = nto_target ();
>>>    if (strcmp (gdbarch_bfd_arch_info (target_gdbarch ())->arch_name, "i386") == 0)
>>> @@ -172,9 +174,13 @@ nto_init_solib_absolute_prefix (void)
>>>  	       == BFD_ENDIAN_BIG ? "be" : "le";
>>>      }
>>>  
>>> -  xsnprintf (arch_path, sizeof (arch_path), "%s/%s%s", nto_root, arch, endian);
>>> +  arch_len = strlen (nto_root) + 1 + strlen (arch) + strlen (endian) + 1;
>>> +  arch_path = alloca (arch_len);
>>> +  xsnprintf (arch_path, arch_len, "%s/%s%s", nto_root, arch, endian);
>>>  
>>> -  xsnprintf (buf, sizeof (buf), "set solib-absolute-prefix %s", arch_path);
>>> +  len = strlen (FMT) - 2 + strlen (arch_path) + 1;
>>> +  buf =  alloca (len);
>>> +  xsnprintf (buf, len, FMT, arch_path);
>>
>> When I define things in the middle of functions/code, I usually #undef
>> them just after I finished using, to avoid conflicts with others
>> #defines.  Specially when the #define is called "FMT", which is very
>> generic IMO.
> 
> Agreed.
> 
> And quite honestly, I find this use of a macro in the middle of
> a function quite ugly and unnecessary, no matter what was done
> before.  My preference mirrors Tom's suggestion, but failing that,
> I'd rather FMT be a const char * or a const char [].

Agreed.

const char fmt[] = "..." is better than 'const char *', as the
latter gives you an unnecessary extra pointer.

Make that 'static const char fmt[] = "...";' even.

But really alloca for potentially large/unbounded buffers is evil.
xstrprintf plus a cleanup would definitely be my preference.

-- 
Pedro Alves


  reply	other threads:[~2013-05-24  8:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-23 16:36 Svante Signell
2013-05-23 17:08 ` Tom Tromey
2013-05-23 17:21   ` Svante Signell
2013-05-23 17:27     ` Tom Tromey
2013-05-23 17:54       ` Svante Signell
2013-05-24  3:01         ` Sergio Durigan Junior
2013-05-24  2:59 ` Sergio Durigan Junior
2013-05-24  4:27   ` Joel Brobecker
2013-05-24  8:53     ` Pedro Alves [this message]
2013-05-24  9:07       ` Svante Signell
2013-05-24  9:13         ` Sergio Durigan Junior
2013-05-27 11:41           ` Svante Signell
2013-05-27 12:10             ` Joel Brobecker
2013-05-27 12:21               ` Svante Signell
2013-05-27 13:48                 ` Svante Signell
2013-05-27 13:57                   ` Svante Signell
2013-05-27 14:31                     ` Joel Brobecker
2013-05-27 15:59                       ` Svante Signell
2013-05-29  9:26                         ` Joel Brobecker
2013-05-29 12:18                           ` Svante Signell
2013-05-27 16:03                       ` New patch: " Svante Signell
2013-05-29  9:42                         ` Joel Brobecker
2013-05-29 12:49                           ` Svante Signell
2013-05-27 14:55                   ` Thomas Schwinge

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=519F2A7A.4050002@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    --cc=svante.signell@gmail.com \
    /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: link
Be 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