dynamically-allocated memory is uninitialized

Mason slash.tmp@free.fr
Mon Nov 14 13:51:00 GMT 2016


On 12/11/2016 08:04, nick wrote:

> On 2016-11-12 01:37 AM, Andrew Pinski wrote:
>
>> Anyways I think the problem is you assume
>> new Record*[N]; will NULL out the array.  It does not.
>
> Shouldn't new overwrite that memory with a null block
> or is new so stupid that it doesn't do this [...]

Hello,

First, while compiler bugs (or bugs in low-level supporting libraries)
do exist, they are rare. Bugs lurk in user code 99.44% of the time.
(I'm told that's a real statistic.)

Second, you expect dynamically-allocated memory to be zeroed. Consider the
case where an app requests a large memory block, and intends to initialize
it to non-0 values. Zeroing such a block would be a pure waste of CPU.

cf. also short-comings of strncpy()

Regards.



More information about the Gcc-help mailing list