Re: Suspect "uninitialised value(s)" error

Paul Floyd <[email protected]> Thu, 12 Oct 2023 09:53:38 +0200
Newsgroups gmane.comp.debugging.valgrind
Message-ID <[email protected]>
On 11/10/2023 23:47, Karl Robillard via Valgrind-users wrote:
> I'm getting the following error on struct members which should absolutely be
> initialized:
>    Conditional jump or move depends on uninitialised value(s)
>
> To begin investigating I did a memset of zero on the entire struct and the
> error goes away.  Now this C++ struct inherits another one and the error is
> reported in C code expecting the base struct.  If I only memset the base
> struct the error is still reported, which should be impossible.
>
> Code summary of the weirdness:
>
>      struct ListDrawState : public DrawState { ... };
>      extern "C" void draw_func(DrawState*);
>
>      ListDrawState ds;
>      memset(&ds, 0, sizeof(DrawState));  // Error in draw_func()

I don't think that this is legal C++. You can't assume that a C++ class 
object has the same kind of memory layout as a POD C struct.

Does this apply in your case?

https://en.cppreference.com/w/cpp/language/ebo

If ListDrawState isn't using EBO then its size will be larger DrawState 
even though it may not add any data members.


In summary, you should either stick to POD structures and then you can 
use memset or else use C++ classes and constructors.


A+

Paul

_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users