This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PR19351, C++] Fix heap overflow in operator new[]


On Sat, Feb 6, 2010 at 7:56 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Sat, Feb 6, 2010 at 7:47 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
>> * Richard Guenther:
>>
>>> Note that it doesn't touch the ABI at all as you only would use
>>> fixed-point types for intermediate computation.
>>
>> You'd need new multiplication routines on some targets.
>
> Yes, of course. ?Or have a generic implementation (that of course
> involves control flow again).
>
>>>> (It's also somewhat unlikely that I'll be able to implement such
>>>> changes to the middle-end, let alone write new expanders for a wide
>>>> range of targets.)
>>>
>>> Well. ?I suppose you should at least show that for targets where
>>> code size is very important (like arm and for example avr) your
>>> proposed change produces reasonable code (which I doubt).
>>
>> For a POD array (for a non-POD array, it's lost in the noise):
>>
>> _Z5allocj:
>> /* prologue: function */
>> /* frame size = 0 */
>> /* stack size = 0 */
>> .L__stack_usage = 0
>> ? ? ? ?cpi r24,11
>> ? ? ? ?cpc r25,__zero_reg__
>> ? ? ? ?brsh .L3
>> ? ? ? ?ldi r22,lo8(24)
>> ? ? ? ?ldi r23,hi8(24)
>> ? ? ? ?rcall __mulhi3
>> ? ? ? ?rcall _Znaj
>> /* epilogue start */
>> ? ? ? ?ret
>> .L3:
>> ? ? ? ?ldi r24,lo8(255)
>> ? ? ? ?ldi r25,hi8(255)
>> ? ? ? ?rcall _Znaj
>> /* epilogue start */
>> ? ? ? ?ret
>>
>> This doesn't look that good, agreed.
>>
>> It's also broken because the code to determine (size_t)-1 failed.
>> What is the correct way to obtain the number of bits in the target
>> size_t type?
>
> It should be TYPE_PRECISION (size_type_node).

Your mistake is to use sizetype instead of size_type_node.  The former
is middle-end specific, the latter is size_t.

> Richard.
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]