summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHauke Mehrtens2026-03-15 22:03:15 +0000
committerHauke Mehrtens2026-03-15 23:49:06 +0000
commitb9034210bd331749673416c6bf389cccd4e23610 (patch)
treefd887ddc845ea446ab3eae01e1aa5c02a2dc9b59
parentd67578d6b7f7541ae29d224c8831acbee338ef63 (diff)
downloadjsonpath-master.tar.gz
main: fix multiple -e/-t expressions after option deferralHEADmaster
Commit e5a07f4 introduced deferred filtering but stored only a single (te_opt, te_source) pair, so each -e/-t option overwrote the previous one and only the last expression was ever evaluated. Replace the single pair with VLA arrays sized to argc (an upper bound on the number of expressions) and process all collected expressions after parsing. Fixes: e5a07f468508 ("main: defer processing until options are processed") Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Link: https://github.com/openwrt/jsonpath/pull/7 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/main.c b/main.c
index 4eb2e5a..5758ab8 100644
--- a/main.c
+++ b/main.c
@@ -465,12 +465,13 @@ int main(int argc, char **argv)
{
bool array_mode = false;
int opt, rv = 0, limit = 0x7FFFFFFF;
- int te_opt = -1;
bool t_e_flag = false;
FILE *input = stdin;
struct json_object *jsobj = NULL;
const char *jserr = NULL, *source = NULL, *separator = " ";
- char *te_source = NULL;
+ int te_opts[argc];
+ char *te_sources[argc];
+ int te_count = 0;
if (argc == 1)
{
@@ -523,8 +524,9 @@ int main(int argc, char **argv)
t_e_flag = true;
// defer parsing and filtering
- te_source = optarg;
- te_opt = opt;
+ te_sources[te_count] = optarg;
+ te_opts[te_count] = opt;
+ te_count++;
break;
case 'q':
@@ -551,8 +553,8 @@ int main(int argc, char **argv)
}
// Handle filtering and other JSON operations
- if(te_opt != -1 && t_e_flag)
- if (!filter_json(te_opt, jsobj, te_source, separator, limit))
+ for (int i = 0; i < te_count; i++)
+ if (!filter_json(te_opts[i], jsobj, te_sources[i], separator, limit))
rv = 1;
out: