I currently have a program where I need to test if a variable passed in as a parameter is uninitialized. So far it seems like this is pretty hard to do in C, so my next idea was to invoke a signal handler to catch the segfault. However, my code isn't calling upon the signal handler when it tries to access the uninitialized variable, like so:
void segfault_sigaction(int signal, siginfo_t *si, void *arg)
{
printf("Caught segfault at address %p\n", si->si_addr);
exit(0);
}
void myfree(void*p, char * file, int line){
struct sigaction sa;
memset(&sa, 0, sizeof(sigaction));
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = segfault_sigaction;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
char up = *((char*)p); //Segfault
EDIT: On Linux system