From 2dc10f3a94c9b605213e7c383d18fe47a687612f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 13 Oct 2015 02:57:17 +0200 Subject: fix va_copy use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libargparser/argparser.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/libargparser') 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); -- cgit v1.2.3-70-g09d2