[LTP] [PATCH 07/15] ujson: writer: Return error when newline() fails

Andrea Cervesato andrea.cervesato@suse.de
Mon Oct 5 15:25:35 CEST 2026


From: Andrea Cervesato <andrea.cervesato@suse.com>

When out_ch(self, '\n') fails, newline() returns 0 instead of 1,
masking output write errors from the caller. ujson_obj_finish() and
ujson_arr_finish() also ignore the newline() return value. Return 1
on write failure and propagate it to the caller.

Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 libs/ujson/ujson_writer.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libs/ujson/ujson_writer.c b/libs/ujson/ujson_writer.c
index 040ae680e..c203ee079 100644
--- a/libs/ujson/ujson_writer.c
+++ b/libs/ujson/ujson_writer.c
@@ -179,7 +179,7 @@ static int do_padd(ujson_writer *self)
 static int newline(ujson_writer *self)
 {
 	if (out_ch(self, '\n'))
-		return 0;
+		return 1;
 
 	if (do_padd(self))
 		return 1;
@@ -261,8 +261,8 @@ int ujson_obj_finish(ujson_writer *self)
 
 	clear_depth_bit(self);
 
-	if (!first)
-		newline(self);
+	if (!first && newline(self))
+		return 1;
 
 	return out_ch(self, '}');
 }
@@ -304,8 +304,8 @@ int ujson_arr_finish(ujson_writer *self)
 
 	clear_depth_bit(self);
 
-	if (!first)
-		newline(self);
+	if (!first && newline(self))
+		return 1;
 
 	return out_ch(self, ']');
 }

-- 
2.51.0



More information about the ltp mailing list