Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
uninitialized memory read
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mark Wooding, post: 3809900"] Comments: * Important style: Use a typedef rather than #define for making type synonyms. * Indentation is nice. * You never read the values of `bit' or `g'. * `mask' has type `unsigned int' but you're passing it to `printf' with a `%d' format specifier which expects a signed `int'. If `mask' is actually representable as an `int' then all will be well; if not, you have undefined behaviour. * The constant FULL_MASK may have signed type. If it has, then FULL_MASK << n may overflow causing undefined behaviour. You probably mean to define FULL_MASK to be 0xffffffffu, but, in fact... * It looks to me as if you're better off including <limits.h> and using UINT_MAX rather than guessing FULL_MASK, which may be either too large to fit in unsigned int, or too small to cover all of the bits. Of course, I don't actually know what you're trying to achieve, so this might be wrong. I'll assume that FULL_MASK either has unsigned type or is capable of representing all of the values necessary. 5 & 31 = 5 /= 0, so the consequent expression is evaluated. ~(FULL_MASK << (5 & 31)) = ~(FULL_MASK << 5) = ~0x1fffffffe0 = -0x1fffffffdf This is then reduced modulo 2^n (maybe it helps to think of this as a 2-adic value, but probably not...), where n is the width of the smaller of unsigned int and whatever type 0xffffffff happens to have on your platform. The result will end 0x...1f; there may or may not be higher- order set bits, depending on the widths of the types involved. So it looks as if all of the bits of mask are properly initialized, though maybe not with what you expected them to be initialized to. So to me it sounds like (a) Purify is wrong, and (b) so is your code. For the record, Valgrind didn't find anything to complain about. -- [mdw] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
uninitialized memory read
Top