]> granicus.if.org Git - jq/commitdiff
Fix jv_load_file() assertion (fix #1410)
authorNicolas Williams <nico@cryptonector.com>
Sat, 20 May 2017 20:47:41 +0000 (15:47 -0500)
committerNicolas Williams <nico@cryptonector.com>
Sat, 20 May 2017 23:53:48 +0000 (18:53 -0500)
src/jv_file.c
src/jv_unicode.c

index a5829a8fbfe18df184e355d6bee5d27b4205bc3f..4c0060fc4d4d32dbc434145cf39e4a22a6c359e0 100644 (file)
@@ -30,10 +30,12 @@ jv jv_load_file(const char* filename, int raw) {
   while (!feof(file) && !ferror(file)) {
     size_t n = fread(buf, 1, sizeof(buf)-max_utf8_len, file);
     int len = 0;
-    if (jvp_utf8_backtrack(buf+(n-1), buf, &len) && len > 0) {
-      if (!feof(file) && !ferror(file)) {
-        n += fread(buf+n, 1, len, file);
-      }
+
+    if (n == 0)
+      continue;
+    if (jvp_utf8_backtrack(buf+(n-1), buf, &len) && len > 0 &&
+        !feof(file) && !ferror(file)) {
+      n += fread(buf+n, 1, len, file);
     }
 
     if (raw) {
index b3a50b2d0ccc87a3bb77aa4d5f08850700191988..d197349f483880e1ea53d073b103a85a6da86d4a 100644 (file)
@@ -9,7 +9,7 @@
 // *missing_bytes.  If there are no leading bytes or an invalid byte is
 // encountered, NULL is returned and *missing_bytes is not altered.
 const char* jvp_utf8_backtrack(const char* start, const char* min, int *missing_bytes) {
-  assert(min < start);
+  assert(min <= start);
   if (min == start) {
     return min;
   }