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.")
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 b5b1330d1..9a164f167 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -1262,7 +1262,7 @@ json_from_stream(FILE *stream)
     struct json *json;
 
     p = json_parser_create(JSPF_TRAILER);
-    for (;;) {
+    while (!(feof(stream) || ferror(stream))) {
         size_t n;
 
         n = fread(buffer, 1, sizeof buffer, stream);
-- 
2.53.0

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

Reply via email to