diff options
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r-- | libgfortran/io/unix.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 5385d8b..b86bd67 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -489,7 +489,13 @@ buf_read (unix_stream * s, void * buf, ssize_t nbyte) /* Is the data we want in the buffer? */ if (s->logical_offset + nbyte <= s->buffer_offset + s->active && s->buffer_offset <= s->logical_offset) - memcpy (buf, s->buffer + (s->logical_offset - s->buffer_offset), nbyte); + { + /* When nbyte == 0, buf can be NULL which would lead to undefined + behavior if we called memcpy(). */ + if (nbyte != 0) + memcpy (buf, s->buffer + (s->logical_offset - s->buffer_offset), + nbyte); + } else { /* First copy the active bytes if applicable, then read the rest |