Fix jv_load_file() assertion (fix #1410)
This commit is contained in:
1 parent
cb3d5aff84
commit
10d66051ef
2 files changed
+6
-4
No files matched your search
+5
-3
@@ -30,11 +30,13 @@ jv jv_load_file(const char* filename, int raw) {
|
|||||||
while (!feof(file) && !ferror(file)) {
|
while (!feof(file) && !ferror(file)) {
|
||||||
size_t n = fread(buf, 1, sizeof(buf)-max_utf8_len, file);
|
size_t n = fread(buf, 1, sizeof(buf)-max_utf8_len, file);
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if (jvp_utf8_backtrack(buf+(n-1), buf, &len) && len > 0) {
|
|
||||||
if (!feof(file) && !ferror(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);
|
n += fread(buf+n, 1, len, file);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
data = jv_string_append_buf(data, buf, n);
|
data = jv_string_append_buf(data, buf, n);
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
// *missing_bytes. If there are no leading bytes or an invalid byte is
|
// *missing_bytes. If there are no leading bytes or an invalid byte is
|
||||||
// encountered, NULL is returned and *missing_bytes is not altered.
|
// encountered, NULL is returned and *missing_bytes is not altered.
|
||||||
const char* jvp_utf8_backtrack(const char* start, const char* min, int *missing_bytes) {
|
const char* jvp_utf8_backtrack(const char* start, const char* min, int *missing_bytes) {
|
||||||
assert(min < start);
|
assert(min <= start);
|
||||||
if (min == start) {
|
if (min == start) {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user