diff --git a/libc/stdio/fread_unlocked.cpp b/libc/stdio/fread_unlocked.cpp index c9d6e5e5..a070ca66 100644 --- a/libc/stdio/fread_unlocked.cpp +++ b/libc/stdio/fread_unlocked.cpp @@ -40,6 +40,8 @@ size_t fread_unlocked(void* ptr, unsigned char* buf = (unsigned char*) ptr; size_t count = element_size * num_elements; + if ( count == 0 ) + return num_elements; if ( fp->buffer_mode == _IONBF ) { diff --git a/libc/stdio/fwrite_unlocked.cpp b/libc/stdio/fwrite_unlocked.cpp index 2dad4f68..2e25222a 100644 --- a/libc/stdio/fwrite_unlocked.cpp +++ b/libc/stdio/fwrite_unlocked.cpp @@ -40,6 +40,8 @@ size_t fwrite_unlocked(const void* ptr, const unsigned char* buf = (const unsigned char*) ptr; size_t count = element_size * num_elements; + if ( count == 0 ) + return num_elements; if ( fp->buffer_mode == _IONBF ) {