fix setting EOF in memio (#1059)

This commit is contained in:
Roman Fomin 2023-05-18 01:17:51 +07:00 committed by GitHub
parent 3483ac7a96
commit feb602580e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,22 +71,24 @@ size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream)
return 0;
}
if (stream->read_eof)
{
stream->eof = true;
}
// Trying to read more bytes than we have left?
items = nmemb;
if (items * size > stream->buflen - stream->position)
{
if (stream->read_eof)
{
stream->eof = true;
}
else
{
stream->read_eof = true;
}
items = (stream->buflen - stream->position) / size;
}
stream->read_eof = (items > 0 ? false : true);
// Copy bytes to buffer
memcpy(buf, stream->buf + stream->position, items * size);