"uninitialized" is either a pointer or a primitive type

See also http://bigblog.tanbin.com/2013/07/c-uninitialized-static-objects-auto.html

1) uninitialized variable of primitive types — contains rubbish
2) uninitialized pointer — very dangerous.

We are treating rubbish as an address! This address may happen to be Inside or Outside this process’s address space.

Read/write on this dereferenced pointer can lead to crashes. See P161 [[understanding and using C pointers]].

There are third-party tools to help identify uninitialized pointers. I think it’s by source code analysis. If function3 receives an uninitialized pointer it would look completely normal to the compiler or runtime.

3) uninitialized class instance? Possible. Every class instance in c++ will have its memory layout well defined, though a field therein may fall into category 1) or 2) above.

4) uninitialized array of pointers could hold wild pointers

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s