From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [pushed] Remove useless NULL check in python.c
Date: Wed, 19 Feb 2020 15:16:00 -0000 [thread overview]
Message-ID: <CAPTJ0XHinQErb9_gbKM-sTqhvkQ_-6WNTdavtbfKqCD4SX1zMw@mail.gmail.com> (raw)
In-Reply-To: <20200219145728.14136-1-tromey@adacore.com>
On Wed, Feb 19, 2020, 18:57 Tom Tromey <tromey@adacore.com> wrote:
> I noticed that do_start_initialization, in python.c, checks the result
> of xmalloc. However, xmalloc cannot fail, so this check is useless.
> This patch also changes the code to use XNEWVEC.
>
> gdb/ChangeLog
> 2020-02-19 Tom Tromey <tromey@adacore.com>
>
> * python/python.c (do_start_initialization): Use XNEWVEC. Remove
> NULL check.
> ---
> gdb/ChangeLog | 5 +++++
> gdb/python/python.c | 7 +------
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 27d6042c618..fbbc159ede3 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -1679,12 +1679,7 @@ do_start_initialization ()
> std::string oldloc = setlocale (LC_ALL, NULL);
> setlocale (LC_ALL, "");
> progsize = strlen (progname.get ());
> - progname_copy = (wchar_t *) xmalloc ((progsize + 1) * sizeof (wchar_t));
> - if (!progname_copy)
> - {
> - fprintf (stderr, "out of memory\n");
> - return false;
> - }
> + progname_copy = XNEWVEC (wchar_t, progsize + 1);
>
Have you considered using STD::wstring instead of this manual memory
management?
count = mbstowcs (progname_copy, progname.get (), progsize + 1);
if (count == (size_t) -1)
> {
> --
> 2.21.1
>
>
next prev parent reply other threads:[~2020-02-19 15:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 14:57 Tom Tromey
2020-02-19 15:16 ` Christian Biesinger via gdb-patches [this message]
2020-02-19 15:35 ` Tom Tromey
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=CAPTJ0XHinQErb9_gbKM-sTqhvkQ_-6WNTdavtbfKqCD4SX1zMw@mail.gmail.com \
--to=gdb-patches@sourceware.org \
--cc=cbiesinger@google.com \
--cc=tromey@adacore.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