Last Updated: February 25, 2016
·
978
· pornel

Prevent getopt_long crash on unknown options

When you parse commandline arguments in C using getopt_long don't forget to terminate the list of options.

Otherwise it will mostly work, but crash when user enters an invalid long option.

static const struct option long_options[] = {
    ...
    {NULL, 0, NULL, 0}, // don't forget the terminator
};