diff options
-rw-r--r-- | src/argparser.c | 16 | ||||
-rw-r--r-- | src/libargparser/argparser.c | 26 |
2 files changed, 26 insertions, 16 deletions
diff --git a/src/argparser.c b/src/argparser.c index 9a0445f..ed1a64d 100644 --- a/src/argparser.c +++ b/src/argparser.c @@ -276,8 +276,9 @@ args_Option args_new_argumentless(void (*trigger)(const char*, const char*), ssi va_list args, cp; size_t i; + va_start(args, alternatives); + va_copy(cp, args); /* va_copy(dest, src) */ - va_start(cp, alternatives); while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -289,7 +290,6 @@ args_Option args_new_argumentless(void (*trigger)(const char*, const char*), ssi rc.trigger = trigger == null ? noop_2 : trigger; rc.alternatives = (const char**)malloc(count * sizeof(const char*)); - va_start(args, alternatives); *(rc.alternatives) = alternatives; for (i = 1; i < count; i++) *(rc.alternatives + i) = va_arg(args, const char*); @@ -316,8 +316,9 @@ args_Option args_new_argumented(void (*trigger)(const char*, const char*, char*) va_list args, cp; size_t i; + va_start(args, alternatives); + va_copy(cp, args); /* va_copy(dest, src) */ - va_start(cp, alternatives); while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -329,7 +330,6 @@ args_Option args_new_argumented(void (*trigger)(const char*, const char*, char*) rc.triggerv = trigger == null ? noop_3 : trigger; rc.alternatives = (const char**)malloc(count * sizeof(const char*)); - va_start(args, alternatives); *(rc.alternatives) = alternatives; for (i = 1; i < count; i++) *(rc.alternatives + i) = va_arg(args, const char*); @@ -357,8 +357,9 @@ args_Option args_new_optargumented(int (*stickless)(const char*), void (*trigger va_list args, cp; size_t i; + va_start(args, alternatives); + va_copy(cp, args); /* va_copy(dest, src) */ - va_start(cp, alternatives); while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -371,7 +372,6 @@ args_Option args_new_optargumented(int (*stickless)(const char*), void (*trigger rc.stickless = stickless == null ? default_stickless : stickless; rc.alternatives = (const char**)malloc(count * sizeof(const char*)); - va_start(args, alternatives); *(rc.alternatives) = alternatives; for (i = 1; i < count; i++) *(rc.alternatives + i) = va_arg(args, const char*); @@ -398,8 +398,9 @@ args_Option args_new_variadic(void (*trigger)(const char*, const char*), const c va_list args, cp; size_t i; + va_start(args, alternatives); + va_copy(cp, args); /* va_copy(dest, src) */ - va_start(cp, alternatives); while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -411,7 +412,6 @@ args_Option args_new_variadic(void (*trigger)(const char*, const char*), const c rc.trigger = trigger == null ? noop_2 : trigger; rc.alternatives = (const char**)malloc(count * sizeof(const char*)); - va_start(args, alternatives); *(rc.alternatives) = alternatives; for (i = 1; i < count; i++) *(rc.alternatives + i) = va_arg(args, const char*); diff --git a/src/libargparser/argparser.c b/src/libargparser/argparser.c index fc5772a..ba3d606 100644 --- a/src/libargparser/argparser.c +++ b/src/libargparser/argparser.c @@ -191,19 +191,24 @@ int args_test_allowed(args_parser_t* parser, ...) va_list args, cp; const char** list; const char* elem; - int rc; + int rc, saved_errno; + + va_start(args, parser); va_copy(cp, args); - va_start(cp, parser); while (va_arg(cp, const char*) != NULL) count++; va_end(cp); if ((list = malloc(count * sizeof(const char*))) == NULL) - return -1; + { + saved_errno = errno; + va_end(args); + errno = saved_errno; + return -1; + } count = 0; - va_start(args, parser); while ((elem = va_arg(args, const char*)) != NULL) list[count++] = elem; va_end(args); @@ -257,19 +262,24 @@ int args_test_exclusiveness(args_parser_t* parser, ...) va_list args, cp; const char** list; const char* elem; - int rc; + int rc, saved_errno; + + va_start(args, parser); va_copy(cp, args); - va_start(cp, parser); while (va_arg(cp, const char*) != NULL) count++; va_end(cp); if ((list = malloc(count * sizeof(const char*))) == NULL) - return -1; + { + saved_errno = errno; + va_end(args); + errno = saved_errno; + return -1; + } count = 0; - va_start(args, parser); while ((elem = va_arg(args, const char*)) != NULL) list[count++] = elem; va_end(args); |