Up until now I have had some code that worked perfectly regarding a variable called wfiles
. wfiles is initialized within my main file:
char* wfiles = "";
Which as far as I can tell C has no complaints. Next the wfiles
variable is allocated in a switch statement:
switch (c) {
case 't':
/* the user wants a template */
template = optarg;
break;
case 'f':
wfiles = optarg;
break;
case 'v':
vcs = optarg;
break;
case 'u':
url = optarg;
break;
case 's':
/* custom save location */
save_loc = optarg;
break;
case '?':
break;
default:
abort();
}
finally I check for whether or not wfiles
is empty:
if (!empty(wfiles))
empty is a macro that expands to (strlen(wfiles) == 0)
I cannot see any problems with this but when I run this code I get a segmentation fault. This had never happened before. When I ran the code in gdb with and without debugging symbols, I get one line pointed to the if statement earlier mentioned. Does anyone know why this is?