Write only memory

D

Dave Thompson

In <[email protected]> jacob navia <[email protected]> writes:

You are naive. Most compilers can detect most attempts to read from
uninitialised memory, when automatically allocated. Statically allocated
memory is always initialised and, for dynamically allocated memory, there
is always calloc.
I assume you mean _simple, scalar, unaliased_ automatic variables.

Which may well be "most" cases, if only because use of such variables
is the most common case of object use.

But there are many uses of uninitialized automatic memory which cannot
(practically, or at all) be detected at compile time:

{
int a, b = 0, *p;
p = some computation that might be &a or &b
*p = 1;
a; // initialized?
}

{
int x[10], i;
for( i = 0; i < 5; i++ ) x = i;
i = some computation that might be < 5 or >= 5
x; // initialized?
}

etc. I do sometimes, if there is any significant complexity to the
logic, default-fill such variables so at least my bugs are Bohr-ing.

- David.Thompson1 at worldnet.att.net
 
D

Dan Pop

In said:
I assume you mean _simple, scalar, unaliased_ automatic variables.

Which may well be "most" cases, if only because use of such variables
is the most common case of object use.

It's also most cases because these are the variables that are left
uninitialised most of the time. People are a lot more careful to
initialise their aggregates than their scalars.

Most of the uncatchable examples are contrived, designed on purpose rather
than arising from real code.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top