Address of pointer throws a segfault in C++

123 views Asked by At

I have a function that is supposed to return a double pointer, it is supposed to return the address of the pointer to a piece of data which in this example is a character array

The original data is sent as a parameter in the constructor

Classname::Classname(void* fdata);

It is then copied to a void* data member called frame_data with

frame_data = fdata;

The function that returns the double pointer is defined as

void** Classname::data(){
    return &frame_data;
}

Finally, the function that later calls data()

std::sprintf(*(char**)classn.data(), "LOOP No: %d", loop);

And this is where the program segfaults. Obviously something is wrong, but I'm just not sure where the problem comes in. In this program the sprintf line isn't changeable, as is the fact that data() returns a double pointer, any idea where I'm going wrong?

0

There are 0 answers