pointers - how can I 'crash proof' a callback function written in C if passed the wrong parameter type -
i have callback function written in c runs on server , must crash proof. is, if expecting integer , passed character string pointer, must internal function determine that, , prevent getting segmentation faults when trying not allowed on wrong parameter type.
the function protoype is:
void callback_function(parameter_type a, const b); and 'a' supposed tell me, via enum, whether 'b' integer or character string pointer. if calling function programmer makes mistake, , tells me in 'a' 'b' integer, , 'b' character string pointer, how determine without crashing callback function code. runs on server , must maintain going if caller function made mistake.
the code has in c, , portable c library extensions not possible. compiler is: gcc v4.8.2 sizeof integer on platform 4, , length of character pointer. integer have same value, numerically, character pointer, , vice versa.
if think character pointer , not, when seek find content of that, of course of study segmentation fault.
if write signal handler handle fault, how "clear" signal, , resume execution @ sane place?
did mention 'b' union defined as:
union param_2 { char * c; int i; } param_to_be_passed; i think that's it.
thank answers.
that not possible.
there's no way "look" @ at pointer , determine if it's valid de-reference, except null-checking of course.
other that, there's no magic way know if pointer points @ character data, integer, function, or else.
c pointers types signals
No comments:
Post a Comment