Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>,
	gdb-patches@sourceware.org
Subject: Re: [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args
Date: Wed, 24 Oct 2018 17:03:00 -0000	[thread overview]
Message-ID: <71de39a2-81ed-ac7e-aa3a-dcd60341319e@redhat.com> (raw)
In-Reply-To: <1540331965.12106.8.camel@skynet.be>

On 10/23/2018 10:59 PM, Philippe Waroquiers wrote:
> On Mon, 2018-10-22 at 15:15 +0100, Pedro Alves wrote:

>> +/* See documentation in cli-utils.h.  */
>>> +
>>> +const char*
>>> +info_print_args_help (const char* prefix,
>>> +		      const char* entity_kind)
> 
> 
>> While at it, why return a copy of the string, instead of returning
>> the std::string directly?
> The returned value is used as argument to add_prefix_cmd,
> that expects a char * that must stay valid when the std::string is destroyed.
> So, at the call site, I cannot use info_print_args_help (...).c_str (),
> as this gives a memory corruption (confirmed by valgrind).

Ah.

> So, I have done:
> +const char *
> +info_print_args_help (const char *prefix,
> +                     const char *entity_kind)
> +{
> +  /*  Note : this returns a string allocated with xstrdup, as this
> +      is typically used as argument to add_prefix_cmd, which needs a
> +      string that stays valid after destruction of the std::string.  */
> +  return xstrdup
> +    (string_printf (_("\
> +%sIf NAMEREGEXP is provided, only prints the %s whose name\n   \
> ....
> 
>  Does this sound ok, or is there a better way to do (e.g. at the call site) ?

Keep the function's interface, but use xstrprintf instead
of 'xstrdup + string_printf' then.

Thanks,
Pedro Alves


  reply	other threads:[~2018-10-24 17:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-23 21:42 [RFAv3 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-09-23 21:42 ` [RFAv3 4/5] Announce changes in NEWS to info [args|functions|locals|variables] Philippe Waroquiers
2018-09-24  6:59   ` Eli Zaretskii
2018-09-23 21:42 ` [RFAv3 3/5] Document changes " Philippe Waroquiers
2018-09-24  7:03   ` Eli Zaretskii
2018-10-22 14:17   ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 2/5] Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args " Philippe Waroquiers
2018-10-22 14:16   ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 5/5] Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-10-22 14:19   ` Pedro Alves
2018-10-23 22:05     ` Philippe Waroquiers
2018-10-24 17:18       ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args Philippe Waroquiers
2018-10-22 14:16   ` Pedro Alves
2018-10-23 21:59     ` Philippe Waroquiers
2018-10-24 17:03       ` Pedro Alves [this message]
2018-10-02 18:17 ` [RFAv3 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-10-11 19:56 ` PING^2 " Philippe Waroquiers
2018-10-18 19:37 ` PING^3 " Philippe Waroquiers

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=71de39a2-81ed-ac7e-aa3a-dcd60341319e@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    /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