diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-10-13 02:57:17 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-10-13 02:57:17 +0200 |
commit | 2dc10f3a94c9b605213e7c383d18fe47a687612f (patch) | |
tree | c45ba90c748a6ec5a3a443f92c4e3f06978d4924 /src/libargparser | |
parent | fix bug reported by textbrowser reported in #15 (diff) | |
download | argparser-2dc10f3a94c9b605213e7c383d18fe47a687612f.tar.gz argparser-2dc10f3a94c9b605213e7c383d18fe47a687612f.tar.bz2 argparser-2dc10f3a94c9b605213e7c383d18fe47a687612f.tar.xz |
fix va_copy use
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/libargparser/argparser.c | 26 |
1 files changed, 18 insertions, 8 deletions
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); |