[LTP] [PATCH 08/15] ujson: writer: Check return value in ESC_FLUSH

Cyril Hrubis chrubis@suse.cz
Fri Oct 9 16:01:10 CEST 2026


Hi!
> ESC_FLUSH ignores the return values of out() and out_str().
> If an output error occurs while flushing escaped characters, the error
> is ignored and writing continues. Check the return values and return
> immediately on failure.
> 
> Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  libs/ujson/ujson_writer.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libs/ujson/ujson_writer.c b/libs/ujson/ujson_writer.c
> index c203ee079..15faca9be 100644
> --- a/libs/ujson/ujson_writer.c
> +++ b/libs/ujson/ujson_writer.c
> @@ -98,10 +98,12 @@ static inline int out_ch(ujson_writer *self, char ch)
>  }
>  
>  #define ESC_FLUSH(esc_char) do {\
> -	out(self, val, i); \
> +	if (out(self, val, i)) \
> +		return 1; \
>  	val += i + 1; \
>  	i = 0; \
> -	out_str(self, esc_char); \
> +	if (out_str(self, esc_char)) \
> +		return 1; \
>  } while (0)

An return in a macro is a bit borderline.

Maybe it would have been cleaner to change the ESC_FLUSH() into a
funciton and return a proper return value that would be stored in the
switch instead.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list