From abb7f3552bf4d4f7ceecd27a1acd344b45ec2454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 2 Jun 2022 11:58:14 +0200 Subject: Fix va_list bug. --- c/pl.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'c/pl.c') diff --git a/c/pl.c b/c/pl.c index 6f7a07d..9a5baee 100644 --- a/c/pl.c +++ b/c/pl.c @@ -7,9 +7,10 @@ Pl(char *szMod, char *szPred, char *szFmt, ...) { int i, iArity; term_t t; - va_list vl; + va_list vl, vl2; va_start(vl, szFmt); + va_copy(vl2, vl); iArity = strlen(szFmt); t = PL_new_term_refs(iArity); @@ -19,14 +20,7 @@ Pl(char *szMod, char *szPred, char *szFmt, ...) { int x; x = va_arg(vl, int); - if (!PL_put_integer(t+i, x)) return 0; - break; - } - case 'A': - { - atom_t x; - x = va_arg(vl, atom_t); - if (!PL_put_atom(t+i, x)) return 0; + if (!PL_put_integer(t+i, x)) goto f; break; } case 'S': @@ -35,42 +29,51 @@ Pl(char *szMod, char *szPred, char *szFmt, ...) char *x; x = va_arg(vl, char *); a = PL_new_atom(x); - if (!PL_put_atom(t+i, a)) return 0; + if (!PL_put_atom(t+i, a)) goto f; break; } + case 'i': + va_arg(vl, int *); + break; + case 's': + va_arg(vl, char **); + break; } } if (!PL_call_predicate(NULL, PL_Q_NORMAL, PL_predicate(szPred, iArity, szMod), t)) - return 0; + goto f; for (i = 0; szFmt[i]; i++) { switch (szFmt[i]) { case 'i': { int *lp; - lp = va_arg(vl, int *); - if (!PL_get_integer(t+i, lp)) return 0; - break; - } - case 'a': - { - atom_t *lp; - lp = va_arg(vl, atom_t *); - if (!PL_get_atom(t+i, lp)) return 0; + lp = va_arg(vl2, int *); + if (!PL_get_integer(t+i, lp)) goto f; break; } case 's': { char **lp; - lp = va_arg(vl, char **); - if (!PL_get_atom_chars(t+i, lp)) return 0; + lp = va_arg(vl2, char **); + if (!PL_get_atom_chars(t+i, lp)) goto f; break; } + case 'I': + va_arg(vl2, int); + break; + case 'S': + va_arg(vl2, char *); + break; } } va_end(vl); + va_end(vl2); return 1; +f: va_end(vl); + va_end(vl2); + return 0; } -- cgit v1.2.3