diff --git a/libs/libc/stdio/lib_libfread_unlocked.c b/libs/libc/stdio/lib_libfread_unlocked.c index 5e56f126d9b65..1fb26b798ddcd 100644 --- a/libs/libc/stdio/lib_libfread_unlocked.c +++ b/libs/libc/stdio/lib_libfread_unlocked.c @@ -126,11 +126,11 @@ ssize_t lib_fread_unlocked(FAR void *ptr, size_t count, FAR FILE *stream) if (gulp_size > 0) { - if (gulp_size > count) + if (gulp_size > remaining) { /* Clip the gulp size to the requested byte count */ - gulp_size = count; + gulp_size = remaining; } memcpy(dest, stream->fs_bufpos, gulp_size);