[PATCH] utils: json: Fix maybe-uninitialized warning in json_parse()

Chaitanya Tata chaitanya.mgit at gmail.com
Thu Sep 10 13:33:19 PDT 2026


json_parse() reads num/dnum through curr_token->number/dnumber right
after setting them based on is_double, so the value that gets read is
always the one that was just written in the same branch. However,
that data flow spans several nested if/else blocks and switch cases
between the write and the read, which is enough to defeat GCC's
flow analysis at -Os: it flags both num and dnum as possibly used
uninitialized, which is fatal for any -Werror build.

Reproduced with plain gcc -Os -Wall -Werror=maybe-uninitialized (GCC
13.3.0), no special build options required. Initialize both at
declaration to keep such builds working.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata at nordicsemi.no>
---
 src/utils/json.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/utils/json.c b/src/utils/json.c
index ebcc969cb..8acb76d23 100644
--- a/src/utils/json.c
+++ b/src/utils/json.c
@@ -270,8 +270,8 @@ struct json_token * json_parse(const char *data, size_t data_len)
 	struct json_token *root = NULL, *curr_token = NULL, *token = NULL;
 	const char *pos, *end;
 	char *str;
-	int num;
-	double dnum;
+	int num = 0;
+	double dnum = 0;
 	bool is_double;
 	unsigned int depth = 0;
 	unsigned int tokens = 0;
-- 
2.43.0




More information about the Hostap mailing list