diff mbox series

[2/5] libs/ujson: Fix "Garbage after JSON string!" in strict mode

Message ID 20241203151530.16882-3-chrubis@suse.cz
State Changes Requested
Headers show
Series First new shell library converted test | expand

Commit Message

Cyril Hrubis Dec. 3, 2024, 3:15 p.m. UTC
In strict mode warnings are converted into errors and filled into the
error buffer rather than being printed right away. That means that we
have to print error buffer after we issue a warning so that it's printed
in the strict mode (UJSON_READER_STRICT) as well.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 libs/ujson/ujson_reader.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Petr Vorel Dec. 16, 2024, 12:33 p.m. UTC | #1
Hi Cyril,

> In strict mode warnings are converted into errors and filled into the
> error buffer rather than being printed right away. That means that we
> have to print error buffer after we issue a warning so that it's printed
> in the strict mode (UJSON_READER_STRICT) as well.

Acked-by: Petr Vorel <pvorel@suse.cz>

nit: maybe add Fixes: before merge?

Kind regards,
Petr
diff mbox series

Patch

diff --git a/libs/ujson/ujson_reader.c b/libs/ujson/ujson_reader.c
index d508f00d3..9f86f25b7 100644
--- a/libs/ujson/ujson_reader.c
+++ b/libs/ujson/ujson_reader.c
@@ -1049,8 +1049,12 @@  void ujson_reader_finish(ujson_reader *self)
 {
 	if (ujson_reader_err(self))
 		ujson_err_print(self);
-	else if (!ujson_reader_consumed(self))
+	else if (!ujson_reader_consumed(self)) {
 		ujson_warn(self, "Garbage after JSON string!");
+
+		if (ujson_reader_err(self))
+			ujson_err_print(self);
+	}
 }
 
 void ujson_reader_free(ujson_reader *buf)