Hi,
I need help with the following:
I am using a C API available in a network simulator. Using the op_ima_obj_svar_get function it takes an object id and the name of the state variable that the user wishes to retrieve and returns a pointer to the variable. Because the state variable can be any type (void*) it must be cast to the appropriate type. DhtT_Key_Bytes is defined in a header file as typedef unsigned char* DhtT_Key_Bytes;
Code:
DhtT_Key_Bytes* nodesNodeID;
DhtT_Key_Bytes predec;
Int intpredec;
nodesNodeID = (DhtT_Key_Bytes *) op_ima_obj_svar_get(rem_proc_objid, "myNodeID");
predec = dht_sup_get_node_predecessor_idealised (*nodesNodeID);
intpredec = sha_get_int_id(predec);
The above works perfectly. Now here’s the problem: I am passing the same to a different function but get an invalid memory access error:
Code:
DhtT_Key_Bytes* predecessorPtr;
Int intPredecessorPtr;
predecessorPtr = (DhtT_Key_Bytes *) op_ima_obj_svar_get(rem_proc_objid, "predecessor");
intPredecessorPtr = sha_get_int_id(*predecessorPtr);
The state variables “myNodeID” and “predecessor” are both of type DhtT_Key_Bytes.
The only difference that I can make out is that the dht_sup_get_node_predecessor_idealised expects a parameter of type DhtT_Key_Bytes whereas the sha_get_int_id expects a parameter of unsigned char digest[ShaC_Bytes].
I have used sha_get_int_id function before and it’s always worked just fine when passing in a variable of type DhtT_Key_Bytes.
I think I’m confused with my pointers. Can someone please help me with this?
Thanks in advance.