Re: Integer overflow in operator new

2007-04-10 Thread Lawrence Crowl
On 4/9/07, Dave Korn <[EMAIL PROTECTED]> wrote: On 09 April 2007 21:49, Lawrence Crowl wrote: >>> The optimization above would be wrong for such machines because >>> the allocation would be smaller than the requested size. >> >> To request a size of ~size_t(0) is to request a size >> of 0xFFF

RE: Integer overflow in operator new

2007-04-09 Thread Dave Korn
On 09 April 2007 21:49, Lawrence Crowl wrote: >>> The optimization above would be wrong for such machines because >>> the allocation would be smaller than the requested size. >> >> To request a size of ~size_t(0) is to request a size >> of 0x or 0xULL that the allocator >

Re: Integer overflow in operator new. Solved? Experimental i686 code.

2007-04-09 Thread J.C. Pizarro
#include // by J.C. Pîzarro ... // This function doesn't touch the ECX register that is touched by OptionC. __volatile__ static const int minus_one = -1; void *__allocate_array_OptionD(size_t num, size_t size) { register unsigned int result; __asm__ __volatile__ ( "imull %2"

Re: Integer overflow in operator new

2007-04-09 Thread Gabriel Dos Reis
"Lawrence Crowl" <[EMAIL PROTECTED]> writes: [...] | Intel has had several popular processors with segmented addresses | including the 8086, 80186, and 80286. (Actually, the 80386 and | successors are segmented, but the operating systems typically hide | that fact.) The also had the i432. | |

Re: Integer overflow in operator new. Solved? Experimental i686 code.

2007-04-09 Thread J.C. Pizarro
#include // by J.C. Pîzarro ... // See http://www.cs.sjsu.edu/~kirchher/CS047/multDiv.html // One-operand imul: & Unsigned mul: // warning: 32 bit, i686, possible risk of -x * -y = valid x * y, ... // warning: it's made quick & dirty, possible to give clobbered situations. // warning:

Re: Integer overflow in operator new

2007-04-09 Thread Joe Buck
On Mon, Apr 09, 2007 at 01:49:09PM -0700, Lawrence Crowl wrote: > On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: > >We've working in linear address spaces. > >How for segmented address spaces? You give me examples. > > Intel has had several popular processors with segmented addresses > includi

Re: Integer overflow in operator new

2007-04-09 Thread Lawrence Crowl
On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: 2007/4/9, Lawrence Crowl <[EMAIL PROTECTED]>: > On 4/7/07, Joe Buck <[EMAIL PROTECTED]> wrote: > > Consider an implementation that, when given > > > > Foo* array_of_foo = new Foo[n_elements]; > > > > passes __compute_size(elements, sizeo

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Andrew Pinski
On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: Of course, i'm a novice because i like and i don't like the GCC development's model. Of course the user manual explains all what I have mentioned in my previous email so it sounds like you like 95% of the other people who don't read the manual

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Mike Stump
On Apr 9, 2007, at 12:14 PM, J.C. Pizarro wrote: How many code's species are they? One for every problem... 7. Code for IPA??? <- i don't know this weird language. Is it with attributes?. 8. Code for GIMPLE??? <- i don't know this weird language. 9. Code for RTL??? <- i don't know this weir

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread J.C. Pizarro
2007/4/9, J.C. Pizarro <[EMAIL PROTECTED]> wrote: 2007/4/9, Andrew Pinski <[EMAIL PROTECTED]> wrote: > On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: > Well lets say this, we already support this to some extend, by using > __builtin_constant_p and then just inlining. Also there exists > alre

Re: Integer overflow in operator new

2007-04-09 Thread Tom Tromey
> "Ross" == Ross Ridge <[EMAIL PROTECTED]> writes: Ross> So long as whatever switch is used to enable this check isn't on by Ross> default and its effect on code size and speed is documented, I don't Ross> think it matters that much what those effects are. Anything that works Ross> should mak

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread J.C. Pizarro
2007/4/9, Andrew Pinski <[EMAIL PROTECTED]>: On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: > 3. To modify the C-preprocessor and/or C/C++ compiler for: >#if argument X is a constant then > use this code specific of constant X >#else if argument Y is not a consta

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
2007/4/9, Lawrence Crowl <[EMAIL PROTECTED]>: On 4/7/07, Joe Buck <[EMAIL PROTECTED]> wrote: > Consider an implementation that, when given > > Foo* array_of_foo = new Foo[n_elements]; > > passes __compute_size(elements, sizeof Foo) instead of > n_elements*sizeof Foo to operator new, wher

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Andrew Pinski
On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: 3. To modify the C-preprocessor and/or C/C++ compiler for: #if argument X is a constant then use this code specific of constant X #else if argument Y is not a constant then use this code specific of non-c

Re: Integer overflow in operator new

2007-04-09 Thread Lawrence Crowl
On 4/7/07, Joe Buck <[EMAIL PROTECTED]> wrote: Consider an implementation that, when given Foo* array_of_foo = new Foo[n_elements]; passes __compute_size(elements, sizeof Foo) instead of n_elements*sizeof Foo to operator new, where __compute_size is inline size_t __compute_size(size_t

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Ian Lance Taylor
"J.C. Pizarro" <[EMAIL PROTECTED]> writes: > To optimize even more the x86, it still has to use: > 1. Use imul instead of mul because it's little bit faster in cycles. > 2. Use jns/js (sign's conditional jump) instead of jnc/jc (carry's > conditional jump). > 3. To modify the C-preprocessor and/or

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread J.C. Pizarro
4. Conditional moves (cmov).

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread J.C. Pizarro
2007/4/9, Joe Buck <[EMAIL PROTECTED]>: On Mon, Apr 09, 2007 at 09:47:07AM -0700, Andrew Pinski wrote: > On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: > >#include > > > >void *__allocate_array_OptionA(size_t num, size_t size) { // 1st best > > unsigned long long tmp = (unsigned long long)

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Joe Buck
On Mon, Apr 09, 2007 at 09:47:07AM -0700, Andrew Pinski wrote: > On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: > >#include > > > >void *__allocate_array_OptionA(size_t num, size_t size) { // 1st best > > unsigned long long tmp = (unsigned long long)size * num; > > if (tmp >= 0x800

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread Andrew Pinski
On 4/9/07, J.C. Pizarro <[EMAIL PROTECTED]> wrote: #include void *__allocate_array_OptionA(size_t num, size_t size) { // 1st best unsigned long long tmp = (unsigned long long)size * num; if (tmp >= 0x8000ULL) tmp=~size_t(0); return operator new[](tmp); } First this just h

Re: Integer overflow in operator new. Solved?

2007-04-09 Thread J.C. Pizarro
#include void *__allocate_array_OptionA(size_t num, size_t size) { // 1st best unsigned long long tmp = (unsigned long long)size * num; if (tmp >= 0x8000ULL) tmp=~size_t(0); return operator new[](tmp); } void *__allocate_array_OptionB(size_t num, size_t size) { // 2nd best u

Re: Integer overflow in operator new

2007-04-09 Thread Joe Buck
On Tue, Apr 10, 2007 at 03:44:26AM +1200, Ross Smith wrote: > On Monday, 9 April 2007 13:09, J.C. Pizarro wrote: > > > > This code is bigger than Joe Buck's. > > > > Joe Buck's code: 10 instructions > > Ross Ridge's code: 16 instructions > > Ross Smith's code: 16 instructions > > Well, yes, but it

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
2007/4/9, Ross Smith <[EMAIL PROTECTED]> wrote: On Monday, 9 April 2007 13:09, J.C. Pizarro wrote: > > This code is bigger than Joe Buck's. > > Joe Buck's code: 10 instructions > Ross Ridge's code: 16 instructions > Ross Smith's code: 16 instructions Well, yes, but it also doesn't have the bug J

Re: Integer overflow in operator new

2007-04-09 Thread Ross Smith
On Monday, 9 April 2007 13:09, J.C. Pizarro wrote: > > This code is bigger than Joe Buck's. > > Joe Buck's code: 10 instructions > Ross Ridge's code: 16 instructions > Ross Smith's code: 16 instructions Well, yes, but it also doesn't have the bug Joe's code had. That was sort of the whole point.

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
#include void *__allocate_array_of_RossRidge(size_t num, size_t size, size_t max_num) { if (num > max_num) size = ~size_t(0); else size *= num; return operator new[](size); } void *__allocate_array_of_JCPizarro(size_t num, size_t size, size_t max_num) { if (num > max_num) retur

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
2007/4/9, Robert Dewar <[EMAIL PROTECTED]>: J.C. Pizarro wrote: > The multiply is signed. It is need more researching a little bit. So what, the low order 32 bits are unaffected. I think this is just confusion on your part! Yes, i accidently eliminated the lines containing the point '.' for

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
2007/4/9, J.C. Pizarro <[EMAIL PROTECTED]> wrote: _Z29__allocate_array_of_RossRidgejjj: [ gcc v3.4.6 : 9 instructions ] movl4(%esp), %edx cmpl12(%esp), %edx # comparing and ?? i lose me movl8(%esp), %eax orl $-1, %eax imull %edx, %e

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
allocate_array_april2007.tar.gz Description: GNU Zip compressed data

Re: Integer overflow in operator new

2007-04-09 Thread J.C. Pizarro
2007/4/9, Ross Ridge <[EMAIL PROTECTED]> wrote: Florian Weimer writes: >Yeah, but that division is fairly expensive if it can't be performed >at compile time. OTOH, if __compute_size is inlined in all places, >code size does increase somewhat. Well, I believe the assumption was that __compute_s

Re: Integer overflow in operator new

2007-04-09 Thread Ross Ridge
Florian Weimer writes: >Yeah, but that division is fairly expensive if it can't be performed >at compile time. OTOH, if __compute_size is inlined in all places, >code size does increase somewhat. Well, I believe the assumption was that __compute_size would be inlined. If you want to minimize code

Re: Integer overflow in operator new

2007-04-08 Thread Joe Buck
> > Florian Weimer writes: > >>I don't think this check is correct. Consider num = 0x3334 and > >>size = 6. It seems that the check is difficult to perform efficiently > >>unless the architecture provides unsigned multiplication with overflow > >>detection, or an instruction to implement __bu

Re: Integer overflow in operator new

2007-04-08 Thread J.C. Pizarro
One instruction more in GCC-4.1.x vs GCC-3.4.6? Joe Buck's code: 10 instructions [ -Os of gcc-4.1.3-20070326 ] __compute_size: pushl %ebp movl%esp, %ebp movl8(%ebp), %eax movl%eax, %edx imull 12(%ebp), %edx cmpl%eax, %edx

Re: Integer overflow in operator new

2007-04-08 Thread J.C. Pizarro
And this tarball. J.C. Pizarro. compute_size_april2007_2.tar.gz Description: GNU Zip compressed data

Re: Integer overflow in operator new

2007-04-08 Thread J.C. Pizarro
Joe Buck wrote: > > > inline size_t __compute_size(size_t num, size_t size) { > > > size_t product = num * size; > > > return product >= num ? product : ~size_t(0); > > > } 2007/4/9, Ross Smith <[EMAIL PROTECTED]> wrote: On Monday, 9 April 2007 10:23, Florian Weimer wrote: > * Ross Rid

Re: Integer overflow in operator new

2007-04-08 Thread J.C. Pizarro
Joe Buck wrote: > > > inline size_t __compute_size(size_t num, size_t size) { > > > size_t product = num * size; > > > return product >= num ? product : ~size_t(0); > > > } 2007/4/9, Ross Smith <[EMAIL PROTECTED]> wrote: On Monday, 9 April 2007 10:23, Florian Weimer wrote: > * Ross Rid

Re: Integer overflow in operator new

2007-04-08 Thread Ross Smith
On Monday, 9 April 2007 10:23, Florian Weimer wrote: > * Ross Ridge: > > Florian Weimer writes: > >>I don't think this check is correct. Consider num = 0x3334 and > >>size = 6. It seems that the check is difficult to perform > >> efficiently unless the architecture provides unsigned > >> mult

Re: Integer overflow in operator new

2007-04-08 Thread Robert Dewar
Bradley Lucier wrote: Robert Dewar wrote: I have always been told that -ftrapv is nowhere near fully working or reliable (I think Eric is the source of that advice). Is this just a rumor, or are there data that backs this up. (That - fwrapv doesn't work, not that Dewar was always told that

Re: Integer overflow in operator new

2007-04-08 Thread Florian Weimer
* Ross Ridge: > Florian Weimer writes: >>I don't think this check is correct. Consider num = 0x3334 and >>size = 6. It seems that the check is difficult to perform efficiently >>unless the architecture provides unsigned multiplication with overflow >>detection, or an instruction to implement

Re: Integer overflow in operator new

2007-04-08 Thread Andrew Haley
Andrew Pinski writes: > On 4/8/07, Bradley Lucier <[EMAIL PROTECTED]> wrote: > > Is this just a rumor, or are there data that backs this up. (That - > > fwrapv doesn't work, not that Dewar was always told that it doesn't > > work.) > > If you look into the bugzilla, you will see now two bug

Re: Integer overflow in operator new

2007-04-08 Thread Andrew Pinski
On 4/8/07, Bradley Lucier <[EMAIL PROTECTED]> wrote: Is this just a rumor, or are there data that backs this up. (That - fwrapv doesn't work, not that Dewar was always told that it doesn't work.) If you look into the bugzilla, you will see now two bugs filed against -ftrapv. One because the r

Re: Integer overflow in operator new

2007-04-08 Thread Bradley Lucier
Robert Dewar wrote: I have always been told that -ftrapv is nowhere near fully working or reliable (I think Eric is the source of that advice). Is this just a rumor, or are there data that backs this up. (That - fwrapv doesn't work, not that Dewar was always told that it doesn't work.) B

Re: Integer overflow in operator new

2007-04-08 Thread Ross Ridge
Joe Buck writes: > inline size_t __compute_size(size_t num, size_t size) { > size_t product = num * size; > return product >= num ? product : ~size_t(0); > } Florian Weimer writes: >I don't think this check is correct. Consider num = 0x3334 and >size = 6. It seems that the check is d

Re: Integer overflow in operator new

2007-04-08 Thread Robert Dewar
Dave Korn wrote: Wouldn't using -ftrapv do what we want? Would a possible answer be to make an ftrapv attribute that could be selectively applied to security-critical library routines such as operator new? I have always been told that -ftrapv is nowhere near fully working or reliable (I thi

Re: Integer overflow in operator new

2007-04-08 Thread Marc Espie
In article <[EMAIL PROTECTED]> you write: >The assert should not overflow. I suggest > >#include >#include >assert( n < SIZE_MAX / sizeof(int) ); > >which requires two pieces of information that the programmer >otherwise wouldn't need, SIZE_MAX and sizeof(type). > >Asking programmers to write ex

Re: Integer overflow in operator new

2007-04-08 Thread Marc Espie
In article <[EMAIL PROTECTED]> you write: >On Fri, Apr 06, 2007 at 06:51:24PM -0500, Gabriel Dos Reis wrote: >> David Daney <[EMAIL PROTECTED]> writes: >> >> | One could argue that issuing some type of diagnostic (either at >> | compile time or run time) would be helpful for people that don't >> |

RE: Integer overflow in operator new

2007-04-08 Thread Dave Korn
On 08 April 2007 13:58, Andreas Schwab wrote: > "Dave Korn" <[EMAIL PROTECTED]> writes: > >> Wouldn't using -ftrapv do what we want? > > -ftrapv only modifies signed arithmetic. Unsigned arithmetic never traps. > > Andreas. Meh, I'm an idiot. Still, maybe we want to create a -futrapv fla

Re: Integer overflow in operator new

2007-04-08 Thread Andreas Schwab
"Dave Korn" <[EMAIL PROTECTED]> writes: > Wouldn't using -ftrapv do what we want? -ftrapv only modifies signed arithmetic. Unsigned arithmetic never traps. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fin

RE: Integer overflow in operator new

2007-04-08 Thread Dave Korn
On 08 April 2007 10:43, Florian Weimer wrote: > * Joe Buck: > >> Consider an implementation that, when given >> >> Foo* array_of_foo = new Foo[n_elements]; >> >> passes __compute_size(elements, sizeof Foo) instead of n_elements*sizeof >> Foo to operator new, where __compute_size is >> >>

Re: Integer overflow in operator new

2007-04-08 Thread Florian Weimer
* Joe Buck: > Consider an implementation that, when given > >Foo* array_of_foo = new Foo[n_elements]; > > passes __compute_size(elements, sizeof Foo) instead of n_elements*sizeof Foo > to operator new, where __compute_size is > > inline size_t __compute_size(size_t num, size_t size) { >

Re: Integer overflow in operator new

2007-04-07 Thread Ross Ridge
Joe Buck writes: >Consider an implementation that, when given > >Foo* array_of_foo = new Foo[n_elements]; > >passes __compute_size(elements, sizeof Foo) instead of n_elements*sizeof Foo >to operator new, where __compute_size is > >inline size_t __compute_size(size_t num, size_t size) { >

Re: Integer overflow in operator new

2007-04-07 Thread Gabriel Dos Reis
[EMAIL PROTECTED] (Ross Ridge) writes: [...] | Gabriel Dos Reis writes: | >I believe you're confused about the semantics. | >The issue here is that the *size of object* requested can be | >represented. That is independent of whether the machine has enough | >memory or not. So, new_handler is

Re: Integer overflow in operator new

2007-04-07 Thread Gabriel Dos Reis
Joe Buck <[EMAIL PROTECTED]> writes: | This is why I suggested that, should we implement a better check, | there should be an option to turn it off, so programmers who cannot | afford an extra byte are taken care of. I agree. -- Gaby

Re: Integer overflow in operator new

2007-04-07 Thread Joe Buck
On Sat, Apr 07, 2007 at 07:41:59AM -0400, Robert Dewar wrote: > J.C. Pizarro wrote: > > >A solution is using the -shared option to generate ".so" library. > > That does not solve things in environments like embedded > environments where there are no shared libraries. > > > >Another future solutio

Re: Integer overflow in operator new

2007-04-07 Thread Joe Buck
On Sat, Apr 07, 2007 at 04:01:57PM -0500, Gabriel Dos Reis wrote: > [EMAIL PROTECTED] (Ross Ridge) writes: > > | Joe Buck writes: > | >If a check were to be implemented, the right thing to do would be to throw > | >bad_alloc (for the default new) or return 0 (for the nothrow new). > | > | Ross Ri

Re: Integer overflow in operator new

2007-04-07 Thread Joe Buck
Gabriel Dos Reis writes: > >I believe you're confused about the semantics. > >The issue here is that the *size of object* requested can be > >represented. That is independent of whether the machine has enough > >memory or not. So, new_handler is a red herring On Sat, Apr 07, 2007 at 06:05:35P

Re: Integer overflow in operator new

2007-04-07 Thread Ross Ridge
[EMAIL PROTECTED] (Ross Ridge) writes: > Well, for example, like all other things that a new_handler can do, > like throwing an exception derived from bad_alloc or calling exit(). > In addition, any number of side effects are possible, like printing > error messages or setting flags. Gabriel Dos R

Re: Integer overflow in operator new

2007-04-07 Thread Gabriel Dos Reis
[EMAIL PROTECTED] (Ross Ridge) writes: | Joe Buck writes: | >If a check were to be implemented, the right thing to do would be to throw | >bad_alloc (for the default new) or return 0 (for the nothrow new). | | Ross Ridge writes: | >What do you do if the user has defined his own operator new that

Re: Integer overflow in operator new

2007-04-07 Thread Ross Ridge
Joe Buck writes: >If a check were to be implemented, the right thing to do would be to throw >bad_alloc (for the default new) or return 0 (for the nothrow new). Ross Ridge writes: >What do you do if the user has defined his own operator new that does >something else? Gabriel Dos Reis writes: >Mor

Re: Integer overflow in operator new

2007-04-07 Thread Daniel Jacobowitz
On Sat, Apr 07, 2007 at 12:15:10PM +0200, Florian Weimer wrote: > * Karl Chen: > > > "4 * n", unchecked, is vulnerable to integer overflow. On IA-32, > > "new int[0x4001]" becomes equivalent to "new int[1]". I've > > verified this on gcc-2.95 through 4.1. For larger objects the > > effects

Re: Integer overflow in operator new

2007-04-07 Thread Gabriel Dos Reis
[EMAIL PROTECTED] (Ross Ridge) writes: | Joe Buck writes: | >If a check were to be implemented, the right thing to do would be to throw | >bad_alloc (for the default new) or return 0 (for the nothrow new). | | What do you do if the user has defined his own operator new that does | something else?

Re: Integer overflow in operator new

2007-04-07 Thread J.C. Pizarro
2007/4/7, Robert Dewar <[EMAIL PROTECTED]>: > > A solution is using the -shared option to generate ".so" library. > > That does not solve things in environments like embedded > environments where there are no shared libraries. Use -Os and "strip --strip-all". And remove code if you don't like it.

Re: Integer overflow in operator new

2007-04-07 Thread J.C. Pizarro
2007/4/7, Robert Dewar <[EMAIL PROTECTED]>: > A solution is using the -shared option to generate ".so" library. That does not solve things in environments like embedded environments where there are no shared libraries. Use -Os and "strip --strip-all". And remove code if you don't like it. >

Re: Integer overflow in operator new

2007-04-07 Thread Robert Dewar
J.C. Pizarro wrote: A solution is using the -shared option to generate ".so" library. That does not solve things in environments like embedded environments where there are no shared libraries. Another future solution is pack the big ".so" library with UPX (Ultimate Packer for eXecutables) or

Re: Integer overflow in operator new

2007-04-07 Thread J.C. Pizarro
2007/4/7, Ross Ridge <[EMAIL PROTECTED]>: Joe Buck writes: >If a check were to be implemented, the right thing to do would be to throw >bad_alloc (for the default new) or return 0 (for the nothrow new). What do you do if the user has defined his own operator new that does something else? The c

Re: Integer overflow in operator new

2007-04-07 Thread Robert Dewar
Florian Weimer wrote: This PR19351, by the way. The most widespread interpretation of the standard is that conforming implementations aren't allowed to raise an exception in this case: the arithmetic is defined to occur in terms of an unsigned type. Well for sure the standard does not allow y

Re: Integer overflow in operator new

2007-04-07 Thread Florian Weimer
* Karl Chen: > "4 * n", unchecked, is vulnerable to integer overflow. On IA-32, > "new int[0x4001]" becomes equivalent to "new int[1]". I've > verified this on gcc-2.95 through 4.1. For larger objects the > effects are exaggerated; smaller counts are needed to overflow. This PR19351, by th

Re: Integer overflow in operator new

2007-04-07 Thread Ross Ridge
Joe Buck writes: >If a check were to be implemented, the right thing to do would be to throw >bad_alloc (for the default new) or return 0 (for the nothrow new). What do you do if the user has defined his own operator new that does something else? >There cases where the penalty for this check coul

Re: Integer overflow in operator new

2007-04-06 Thread Joe Buck
On Fri, Apr 06, 2007 at 06:51:24PM -0500, Gabriel Dos Reis wrote: > David Daney <[EMAIL PROTECTED]> writes: > > | One could argue that issuing some type of diagnostic (either at > | compile time or run time) would be helpful for people that don't > | remember to write correct code 100% of the time

Re: Integer overflow in operator new

2007-04-06 Thread Karl Chen
> On 2007-04-06 16:12 PDT, Lawrence Crowl writes: Lawrence> Asking programmers to write extra code for rare Lawrence> events, has not been very successful. Well put Lawrence, I agree; I didn't expect strong opposition. I doubt we'd find much code in the wild that checks for integer o

Re: Integer overflow in operator new

2007-04-06 Thread Gabriel Dos Reis
"J.C. Pizarro" <[EMAIL PROTECTED]> writes: [...] | But if someone implements one fastest bucket-based quickallocator then | the performance penalty with this check is considerable. I would like to see the actual performance penalty numbers for such thingy deployed in the real world. -- Gaby

Re: Integer overflow in operator new

2007-04-06 Thread J.C. Pizarro
06 Apr 2007 18:53:47 -0500, Gabriel Dos Reis <[EMAIL PROTECTED]>: "J.C. Pizarro" <[EMAIL PROTECTED]> writes: [...] | > The compiler should be able to eliminate many of the conditionals. | Yes but no, there are cases that the compiler can't eliminate the | conditionals that depend on run-time, e

Re: Integer overflow in operator new

2007-04-06 Thread Gabriel Dos Reis
"J.C. Pizarro" <[EMAIL PROTECTED]> writes: | > Good points. | > | > Regarding negatives, I believe 'operator new' takes a size_t, | > which is unsigned, but if it were signed it, the multiplication | > would indeed be in danger of creating a negative. | > | > If possible, I would prefer a solution

Re: Integer overflow in operator new

2007-04-06 Thread Gabriel Dos Reis
"J.C. Pizarro" <[EMAIL PROTECTED]> writes: [...] | > The compiler should be able to eliminate many of the conditionals. | Yes but no, there are cases that the compiler can't eliminate the | conditionals that depend on run-time, e.g., "n" is non-constant parameter. What is the performance penalty

Re: Integer overflow in operator new

2007-04-06 Thread Gabriel Dos Reis
David Daney <[EMAIL PROTECTED]> writes: | One could argue that issuing some type of diagnostic (either at | compile time or run time) would be helpful for people that don't | remember to write correct code 100% of the time. I raised this very issue a long time ago; a long-term GCC contributor voc

Re: Integer overflow in operator new

2007-04-06 Thread J.C. Pizarro
The assert should not overflow. I suggest #include #include assert( n < SIZE_MAX / sizeof(int) ); which requires two pieces of information that the programmer otherwise wouldn't need, SIZE_MAX and sizeof(type). Asking programmers to write extra code for rare events, has not been very succes

Re: Integer overflow in operator new

2007-04-06 Thread Lawrence Crowl
On 4/6/07, Andrew Pinski <[EMAIL PROTECTED]> wrote: On 4/6/07, Karl Chen <[EMAIL PROTECTED]> wrote: > Regarding negatives, I believe 'operator new' takes a size_t, > which is unsigned, but if it were signed it, the multiplication > would indeed be in danger of creating a negative. Actually if it

Re: Integer overflow in operator new

2007-04-06 Thread J.C. Pizarro
Good points. Regarding negatives, I believe 'operator new' takes a size_t, which is unsigned, but if it were signed it, the multiplication would indeed be in danger of creating a negative. If possible, I would prefer a solution that's built-in to operator new. I was thinking it should be implem

Re: Integer overflow in operator new

2007-04-06 Thread David Daney
Andrew Pinski wrote: On 4/6/07, Karl Chen <[EMAIL PROTECTED]> wrote: Regarding negatives, I believe 'operator new' takes a size_t, which is unsigned, but if it were signed it, the multiplication would indeed be in danger of creating a negative. Actually if it was signed, the whole result would

Re: Integer overflow in operator new

2007-04-06 Thread Andrew Pinski
On 4/6/07, Karl Chen <[EMAIL PROTECTED]> wrote: Regarding negatives, I believe 'operator new' takes a size_t, which is unsigned, but if it were signed it, the multiplication would indeed be in danger of creating a negative. Actually if it was signed, the whole result would be undefined if there

Re: Integer overflow in operator new

2007-04-06 Thread Karl Chen
> On 2007-04-06 15:35 PDT, J C Pizarro writes: J> A possible workaround could be it but it's vulnerable if J> it's defined with -DNDEBUG : J> int * allocate_int(size_t n) { J> // it's another integer overflow, a positive can J> // become to a negative.

Re: Integer overflow in operator new

2007-04-06 Thread J.C. Pizarro
2007/4/6, Karl Chen <[EMAIL PROTECTED]>: Hi all, apologies if this has been discussed before, but I couldn't find anything about this issue in gcc mailing list archives. Use of operator new (et al) appears to have an integer overflow; this function: int * allocate_int(size_t n) {