From 3c096565ea410ef9ec911a582865ed667018ebf9 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Tue, 3 Mar 2026 12:31:01 +0100 Subject: [PATCH] Fix optional params always using index 0 in ptools_backend_call (#304) Loop variable j was declared inside the loop and reset to 0 on every iteration. All branches had early continue, so j++ never executed. Change j to i - reqParCnt to correctly index into optionalParams array. Also fix paramtype check to use j instead of i. Fixes GH #215 Co-authored-by: Levi Neely --- pclsync/ptools.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pclsync/ptools.c b/pclsync/ptools.c index 07fb4f2..50fe1b2 100644 --- a/pclsync/ptools.c +++ b/pclsync/ptools.c @@ -258,30 +258,28 @@ int ptools_backend_call(const char *binapi, const char *wsPath, // Add optional parameters to the structure for (i = reqParCnt; i < totalParCnt; i++) { - int j = 0; + int j = i - reqParCnt; - if (optionalParams->Params[i].paramtype == 0) { + if (optionalParams->Params[j].paramtype == 0) { localParams[i] = (binparam)PAPI_STR(optionalParams->Params[j].paramname, optionalParams->Params[j].str); continue; } - if (optionalParams->Params[i].paramtype == 1) { + if (optionalParams->Params[j].paramtype == 1) { localParams[i] = (binparam)PAPI_NUM(optionalParams->Params[j].paramname, optionalParams->Params[j].num); continue; } - if (optionalParams->Params[i].paramtype == 2) { + if (optionalParams->Params[j].paramtype == 2) { localParams[i] = (binparam)PAPI_BOOL(optionalParams->Params[j].paramname, optionalParams->Params[j].num); continue; } - - j++; } for (i = 0; i < totalParCnt; i++) {