I am trying to debug a crash issue where memcpy
is trying to access a memory location which does not exist and fails. Following is a reduced version of the problem code:
void func_foo(int **a) {
int *b, c;
if (*a) {
b = *a;
}
memcpy(&c, b, sizeof(int));//this crashes because address "b" is not accessible.
}
My question is: is there a way I can check if memory is accessible before attempting the memcpy
, or is there another protection mechanism to prevent the crash here? Would not checking **a
cause a crash as well in this case?