From bae7db306398915977674d032b5d0f9b7fca3769 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 6 Jul 2011 22:42:57 +0200 Subject: [PATCH] beecut: fixed handling of options fixing a bug that led to a segmentation fault if an empty delimeter was provided. --- src/beecut/beecut.c | 53 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/beecut/beecut.c b/src/beecut/beecut.c index 03131be..22d4b0a 100644 --- a/src/beecut/beecut.c +++ b/src/beecut/beecut.c @@ -25,7 +25,7 @@ #define BEECUT_MAJOR 0 #define BEECUT_MINOR 2 -#define BEECUT_PATCHLVL 0 +#define BEECUT_PATCHLVL 1 #define OPT_DELIMETER 'd' #define OPT_SHORT 's' @@ -94,34 +94,31 @@ int main(int argc, char *argv[]) }; while ((c = getopt_long_only(argc, argv, "d:s", long_options, &option_index)) != -1) { - - if(c == OPT_DELIMETER) { - delimeter = optarg[0]; - continue; - } - - if(c == OPT_SHORT) { - opt_short = 1; - continue; - } - - if(c == OPT_HELP) { - printf("\n"); - print_version(); - printf("\n"); - print_full_usage(); - exit(0); - } - - if(c == OPT_VERSION) { - print_version(); - exit(0); + + switch (c) { + case OPT_DELIMETER: + if (!optarg[0] || optarg[1]) { + fprintf(stderr, "invalid delimeter '%s'\n", optarg); + exit(1); + } + delimeter = optarg[0]; + break; + + case OPT_SHORT: + opt_short = 1; + break; + + case OPT_HELP: + printf("\n"); + print_version(); + printf("\n"); + print_full_usage(); + exit(0); + + case OPT_VERSION: + print_version(); + exit(0); } - - if(opterr) - continue; - - fprintf(stderr, "YOU HIT A BUG #001 opterr=%d c='%c'\n", opterr, delimeter); } /* end while getopt_long_only */ if(argc-optind < 1) {