Uninitialized Byte Valgrind Complaint - Inexplicable

Valgrind continues to complain about uninitialized bytes and truncate in search of a minimal example. I ended up with this:

#include <valgrind/memcheck.h> struct dummyObject{ int foo; bool bar; dummyObject():foo(1),bar(true) {} }; int main(){ dummyObject dummy; VALGRIND_CHECK_VALUE_IS_DEFINED(dummy); return 0; } 

Having two ints or two bools, or one int or bool, does not cause any complaints. It seems that having a class with members of different types leads to a Valgrind complaint. This is not only related to my explicit request for verification; in a larger program that uses an object similar to dummyObject, I get the error "Conditional jump or move depends on the error of an uninitialized value".

My compiler is g ++ 4.7.3 on 64-bit Linux, compiling with debug flags and without optimization - or with, it does not matter.

Is there something I am missing or is it a false positive?

+4
source share
1 answer

When you check the size of your type, you will probably find that the size does not match the sum of the size of the members. For example, on my system, I get:

 sizeof(dummy)=8 sizeof(int)=4 sizeof(bool)=1 

when printing different sizes. The difference is in the add-on used to ensure that objects are tied to addresses that they can easily access by the system. This add-on is probably uninitialized.

+3
source

Source: https://habr.com/ru/post/1501960/


All Articles