public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: Joe Buck <Joe.Buck@synopsys.com>
Cc: Florian Weimer <fw@deneb.enyo.de>,
	Chris Lattner <clattner@apple.com>,
		"Joseph S. Myers" <joseph@codesourcery.com>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: operator new[] overflow (PR 19351)
Date: Thu, 02 Dec 2010 22:47:00 -0000	[thread overview]
Message-ID: <AANLkTikTyVP_HPHezd+ZuwXLnMyakSjNtsN=hh0UOc+s@mail.gmail.com> (raw)
In-Reply-To: <20101202202014.GI9549@synopsys.com>

On Thu, Dec 2, 2010 at 2:20 PM, Joe Buck <Joe.Buck@synopsys.com> wrote:
> On Wed, Dec 01, 2010 at 10:26:58PM -0800, Florian Weimer wrote:
>> * Chris Lattner:
>>
>> > On overflow it just forces the size passed in to operator new to
>> > -1ULL, which throws bad_alloc.
>>
>> This is also what my patch tries to implement.
>
> Yes, but Chris's code just checks the overflow of the multiply.  Your
> patch achieves the same result in a more complex way, by
> computing the largest non-overflowing value of n in
>
> new T[n];
>
> and comparing n against that.  Even though max_size_t/sizeof T is a
> compile-time constant, this is still more expensive.

I would expect max_size_t/sizeof(T) to be actually an integer
constant that n is compared against.  I would be surprised
if that one-time comparison is noticeable in real applications that
new an array of objects.

>
>

  reply	other threads:[~2010-12-02 22:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-30 21:34 Florian Weimer
2010-11-30 22:38 ` Joseph S. Myers
2010-11-30 22:56   ` Gabriel Dos Reis
     [not found]     ` <20101130231211.GI13905@synopsys.com>
2010-12-01 23:36       ` Chris Lattner
2010-12-02  2:51         ` Gabriel Dos Reis
2010-12-02  6:27         ` Florian Weimer
2010-12-02 20:20           ` Joe Buck
2010-12-02 22:47             ` Gabriel Dos Reis [this message]
2010-12-03 17:31               ` Joe Buck
2010-12-04 13:23                 ` Florian Weimer
2010-12-04 16:09                   ` Gabriel Dos Reis
2011-01-22 20:09                     ` Florian Weimer
2010-12-05  7:56                   ` Chris Lattner
2010-12-05 11:19                     ` Richard Guenther
2010-12-05 17:49                       ` Chris Lattner
2010-12-05 17:54                         ` Chris Lattner
2010-12-05 20:52                         ` Richard Guenther
2010-12-05 21:21                           ` Joseph S. Myers
2010-12-05 21:44                             ` Richard Guenther

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='AANLkTikTyVP_HPHezd+ZuwXLnMyakSjNtsN=hh0UOc+s@mail.gmail.com' \
    --to=gdr@integrable-solutions.net \
    --cc=Joe.Buck@synopsys.com \
    --cc=clattner@apple.com \
    --cc=fw@deneb.enyo.de \
    --cc=gcc@gcc.gnu.org \
    --cc=joseph@codesourcery.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).