diff options
author | Nicolas Williams <nico@cryptonector.com> | 2017-05-20 15:47:41 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2017-05-20 18:53:48 -0500 |
commit | 10d66051ef600c9ec8c7bcf2e029d0e87f0d981c (patch) | |
tree | 16a3cce9a9051facfad5d25d9a69b395b955d1aa | |
parent | cb3d5aff845c78172090e7ec3c52f0b8c8e05c78 (diff) |
Fix jv_load_file() assertion (fix #1410)
-rw-r--r-- | src/jv_file.c | 10 | ||||
-rw-r--r-- | src/jv_unicode.c | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/jv_file.c b/src/jv_file.c index a5829a8f..4c0060fc 100644 --- a/src/jv_file.c +++ b/src/jv_file.c @@ -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) { diff --git a/src/jv_unicode.c b/src/jv_unicode.c index b3a50b2d..d197349f 100644 --- a/src/jv_unicode.c +++ b/src/jv_unicode.c @@ -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; } |