[LTP] [PATCH 04/15] ujson: writer: Fix open() return value check
Andrea Cervesato
andrea.cervesato@suse.de
Mon Oct 5 15:25:32 CEST 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
open() returns -1 on failure and a non-negative file descriptor on
success (including 0). Checking !writer_file->fd wrongly rejects fd 0
as an error and accepts -1 on open failure. Check for negative fd
instead.
Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
libs/ujson/ujson_writer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/ujson/ujson_writer.c b/libs/ujson/ujson_writer.c
index b5da494d1..040ae680e 100644
--- a/libs/ujson/ujson_writer.c
+++ b/libs/ujson/ujson_writer.c
@@ -475,7 +475,7 @@ ujson_writer *ujson_writer_file_open(const char *path)
writer_file = (void*)ret + sizeof(ujson_writer);
writer_file->fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0664);
- if (!writer_file->fd) {
+ if (writer_file->fd < 0) {
free(ret);
return NULL;
}
--
2.51.0
More information about the ltp
mailing list