I am writing a C++ service that needs to populate a struct nested within a struct as a response to a service call. I have been able to do it with gsoap 2.8.3 without a problem. After updating to 2.8.59 the variables inside the inner struct are being held as pointers for some reason (I am using the same header file to generate the gsoap code so it is not that I am making them pointers in the header).
int Example::myFunction(_ns2__incomingNestedStruct *ns2__incomingNestedStruct,
ns2__nestedStructResponse &ns2__nestedStructReturn_)
{
// gsoap 2.8.3, works fine
ns2__nestedStructReturn_.NameOfInnerStruct.variableOneName = 3;
// gsoap 2.8.59, causes the program to crash
int testVar = 3;
ns2__nestedStructReturn_.NameOfInnerStruct->variableOneName = &testVar;
}
If I don't populate the return struct the function calls works fine. The program crashes with this exception:
Unhandled exception at 0x000000013F9A230B in programName.exe: 0xC0000005: Access violation writing location 0x0000000000000008.
I have tried making "testVar"
a member variable but that didn't work either. How can I populate the inner struct without crashing? Is there a way to make gsoap 2.8.59 not use a pointer to hold the member variables?
Try to make the int testVar as global variable I mean declare it outside function and assign value 3 inside function.
It turns out the inner struct is also being held as a pointer. After dynamically allocating it the variables then have to be dynamically allocated (in this order) as well. The pointers can also be set to the addresses of member variables.
User contributions licensed under CC BY-SA 3.0