]> granicus.if.org Git - jq/commitdiff
Stop warning on fgets, complex version
authorBrendan Macmillan <melbourne.research@gmail.com>
Fri, 31 May 2013 04:21:55 +0000 (14:21 +1000)
committerBrendan Macmillan <melbourne.research@gmail.com>
Sat, 1 Jun 2013 01:03:15 +0000 (11:03 +1000)
jq_test.c

index 25cea1c696f7420882e9967fe1b15068e51bc4d4..d05b7be2195ea4929fff7b1f7ec12d1c231f08e1 100644 (file)
--- a/jq_test.c
+++ b/jq_test.c
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 #include "jv.h"
 #include "execute.h"
 
@@ -39,7 +40,11 @@ static void run_jq_tests(FILE *testdata) {
     printf("Disassembly:\n");
     dump_disassembly(2, bc);
     printf("\n");
-    fgets(buf, sizeof(buf), testdata);
+    if (!fgets(buf, sizeof(buf), testdata)) {
+      invalid++;
+      printf("%s\n", (errno==0)?"Premature EOF":strerror(errno));
+      break;
+    }
     jv input = jv_parse(buf);
     if (!jv_is_valid(input)){ invalid++; continue; }
     jq_init(bc, input, &jq, JQ_DEBUG_TRACE);