aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-13 02:57:17 +0200
committerMattias Andrée <maandree@operamail.com>2015-10-13 02:57:17 +0200
commit2dc10f3a94c9b605213e7c383d18fe47a687612f (patch)
treec45ba90c748a6ec5a3a443f92c4e3f06978d4924 /src
parentfix bug reported by textbrowser reported in #15 (diff)
downloadargparser-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 'src')
-rw-r--r--src/argparser.c16
-rw-r--r--src/libargparser/argparser.c26
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);