Skip to content

Commit

Permalink
Fix db_fread
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Mar 5, 2024
1 parent 99315ee commit ef27a64
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/plib/db/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ef27a64

Please sign in to comment.