lundi 22 avril 2019

Valgrind unitialized bytes error due to type casting bit field to integer

struct A {
    A() : a(0), b_1(0), b_2(0), c(0) {}
    int a=0;
    int b_1: 9;
    int b_2: 23;
    int c=0;
};

void func1(int i, int j, int k) {   //<<<< valgrind error at this line.
}

void func2() {
    int aa = 11;
    int cc = 12;
    A a;
    func1(2, a.b_2, cc );
}

My program has something like this. I am getting a valgrind error like below:

==25167== Uninitialised value was created by a stack allocation
==25167==    at 0x122A00E9: func1(int, int, int)

I am suspecting because a.b_2 is 23 bits, and we are assigning it to 32 bit integer j, this is causing uninitialized bytes error? is this correct?

Aucun commentaire:

Enregistrer un commentaire