From: Klee Dienes <klee@apple.com>
To: Andrew Cagney <ac131313@redhat.com>
Cc: Alan Modra <amodra@bigpond.net.au>,
binutils@sources.redhat.com, gdb@sources.redhat.com
Subject: Re: [RFA] Replace strdup with xstrdup in tic30-dis.c
Date: Tue, 19 Nov 2002 18:05:00 -0000 [thread overview]
Message-ID: <E3F5CE00-FC28-11D6-8F9D-00039396EEB8@apple.com> (raw)
In-Reply-To: <3DDAB683.6010005@redhat.com>
Another option would be to add a xmalloc_set_failure_handler() to
libiberty for use by GDB.
Regardless of what we plan to do though, I argue that replacing
unchecked malloc() and strdup() calls in opcodes/ with xmalloc and
xstrdup is a useful step forward. The real bug in the code is the lack
of checking the return value; using malloc instead of xmalloc is just
sweeping the problem under the rug. Using xmalloc may not be the final
solution, but at least it prevents random unknown crashes, and marks
the location of the bug for a later "go through and fix all the xmalloc
calls" pass.
I'm not arguing against a "no xmalloc in new code" rule, just that an
unchecked xmalloc is better than an unchecked malloc.
On Tuesday, November 19, 2002, at 05:09 PM, Andrew Cagney wrote:
>> On Tue, Nov 19, 2002 at 11:26:12AM -0500, Andrew Cagney wrote:
>>> I know BFD intentionally doesn't use the x*() functions. Instead it
>>> tries to clean up and return an error indication when there is a
>>> malloc() failure.
>>> What of the disassembler though? GDB, which is depending on the
>>> disassembler, needs to be able to recover from low memory (aka
>>> malloc() failure) conditions.
>> I OK'd the patch too quickly, then remembered the no xmalloc rule..
>> Then on grepping through opcodes/*, I saw so many xmalloc and xstrdup
>> calls that I hardly felt like correcting the patch. We're no worse
>> off with an xstrdup call than an unchecked strdup call. :-(
>
> Perhaphs the coding standard applies to just bfd?
>
> Assuming it does apply to opcodes/, remember, you've got to start
> somewhere. One good pace to start is to stop the addition of further
> stray xmalloc() calls.
>
> Andrew
>
>
next prev parent reply other threads:[~2002-11-20 2:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <555D137A-FB43-11D6-84AF-00039396EEB8@apple.com>
[not found] ` <20021119071305.GM997@bubble.sa.bigpond.net.au>
2002-11-19 8:26 ` Andrew Cagney
2002-11-19 13:42 ` Alan Modra
2002-11-19 14:09 ` Andrew Cagney
2002-11-19 18:05 ` Klee Dienes [this message]
2002-11-20 8:05 ` Andrew Cagney
2002-11-20 15:09 ` Alan Modra
2002-11-20 22:56 ` Klee Dienes
2002-11-26 14:03 ` Andrew Cagney
2002-11-26 14:37 ` Alan Modra
2002-11-26 15:28 ` Ian Lance Taylor
2002-11-26 15:57 ` Alan Modra
2002-11-26 16:15 ` Andrew Cagney
2002-11-27 16:44 ` Hans-Peter Nilsson
2002-11-27 21:55 ` Ian Lance Taylor
2002-11-28 14:39 ` Alan Modra
2002-11-28 15:23 ` Andrew Cagney
2002-11-28 21:04 ` Alan Modra
2002-11-29 0:41 ` Doug Evans
2002-11-29 4:02 ` Ben Elliston
2002-11-26 15:58 ` Klee Dienes
2002-11-27 11:37 ` David O'Brien
2002-11-26 16:23 Doug Evans
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=E3F5CE00-FC28-11D6-8F9D-00039396EEB8@apple.com \
--to=klee@apple.com \
--cc=ac131313@redhat.com \
--cc=amodra@bigpond.net.au \
--cc=binutils@sources.redhat.com \
--cc=gdb@sources.redhat.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