Skip to content

Commit

Permalink
Fix jv_load_file() assertion (fix jqlang#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed May 20, 2017
1 parent cb3d5af commit 10d6605
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/jv_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/jv_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 10d6605

Please sign in to comment.