From 2a5b760fb18f1f44d14bdd311d97f6e3b39a1382 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 25 Nov 2025 18:57:19 +0100 Subject: [PATCH] improve json parsing in load_config --- application/settings.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/application/settings.c b/application/settings.c index e0cc967..8faf849 100644 --- a/application/settings.c +++ b/application/settings.c @@ -125,16 +125,17 @@ int load_config(void) { CxJsonValue *value = NULL; char buf[JS_READ_BUFSIZE]; size_t r; - while((ret = cxJsonNext(&parser, &value)) != CX_JSON_NO_ERROR) { - if(ret > CX_JSON_NULL_DATA) { - fprintf(stderr, "Error: cannot parse config file: %s\n", cfgfile_path); - break; // error - } + + do { r = fread(buf, 1, JS_READ_BUFSIZE, cfgfile); if(r == 0) { break; } cxJsonFilln(&parser, buf, r); + } while((ret = cxJsonNext(&parser, &value)) != CX_JSON_NO_ERROR); + + if(ret > CX_JSON_NULL_DATA) { + fprintf(stderr, "Error: cannot parse config file: %s\n", cfgfile_path); } cxJsonDestroy(&parser); -- 2.47.3