From 0cbafe1ed07a565a4831527422ca0cf9241aee5e Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Tue, 28 Jul 2015 17:38:13 +0200 Subject: [PATCH] make argc macro a bit safer --- src/optparse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/optparse.c b/src/optparse.c index 911a56be..f6fb7e77 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -5,7 +5,7 @@ snprintf(options->errmsg, sizeof(options->errmsg), format, args); #define options_argv(i) \ - (i) < options->argc ? options->argv[i] : 0; + ((i) < options->argc ? options->argv[i] : NULL) void optparse_init(struct optparse *options, int argc, char **argv) { @@ -156,7 +156,7 @@ optstring_from_long(const struct optparse_long *longopts, char *optstring) for (int i = 0; !longopts_end(longopts, i); i++) { if (longopts[i].shortname) { *p++ = longopts[i].shortname; - for (int a = 0; a < longopts[i].argtype; a++) + for (unsigned int a = 0; a < longopts[i].argtype; a++) *p++ = ':'; } } @@ -210,6 +210,7 @@ optparse_long(struct optparse *options, const struct optparse_long *longopts, int *longindex) { +// printf("%i < %i\n",options->optind,options->argc); char *option = options_argv(options->optind); if (option == NULL) { return -1; -- 2.47.2