Fix db_fread

This commit is contained in:
Alexander Batalov 2024-03-05 20:22:40 +03:00
parent 99315ee761
commit ef27a64686

View File

@ -759,11 +759,13 @@ size_t db_fread(void* ptr, size_t size, size_t count, DB_FILE* stream)
if (elements_read != 0) {
if (fseek(stream->database->stream, stream->field_18, SEEK_SET) == 0) {
if (read_callback != NULL) {
// FIXME: Probably error - mixing elements and
// bytes in `elements_read` without resetting.
remaining_size = elements_read * size;
chunk_size = read_threshold - read_count;
// CE: Reuse `elements_read` to represent
// number of bytes read.
elements_read = 0;
while (remaining_size >= chunk_size) {
bytes_read = fread(buf, 1, chunk_size, stream->database->stream);
buf += bytes_read;