Previously json_from_stream() read a file until a 0 byte read.  Clang
complained that fread on a file in eof or error state is an undefined
behaviour.

Found with clang analyze.

Fixes: f38b84ea2b6b ("Implement JSON parsing and serialization.")
Acked-by: Eelco Chaudron <[email protected]>
Signed-off-by: Mike Pattrick <[email protected]>
---
 lib/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/json.c b/lib/json.c
index 23000f195..ece61ad21 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -1261,7 +1261,7 @@ json_from_stream(FILE *stream)
     struct json *json;
 
     p = json_parser_create(JSPF_TRAILER);
-    for (;;) {
+    while (!(feof(stream) || ferror(stream))) {
         char buffer[BUFSIZ];
         size_t n;
 
-- 
2.54.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to