Reputation: 63
I'm having some trouble with c code from a library that I use with Android NDK.
It works on the emulator, but not on a real device. It gives me a "libc - Fatal signal 11" (SIGSEGV)
I have traced the problem to a piece of code in the library, but I'm having trouble understanding what the second line does.
Here is the code:
int lookup_mpz(mpz_t z, const char *(*tab)(const char *), const char *key) {
const char *data= tab(key); //--> Causes SEGV
if (!data) {
pbc_error("missing param: `%s'", key);
return 1;
}
mpz_set_str(z, tab(key), 0);
return 0;
}
Upvotes: 3
Views: 1214
Reputation: 121971
The second line is invoking a function, via a function pointer named tab
. The function has the signature:
const char* f(const char*);
Suggest checking that key
and tab()
are not NULL prior to calling tab()
.
Upvotes: 2