aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/unix.c
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>2015-09-12 12:05:44 +0000
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2015-09-12 12:05:44 +0000
commit76b88c5fc9930734f4d3496b9100862f62311ce5 (patch)
tree178a900d2d4f9108057640a6f3190da9cedbade1 /libgfortran/io/unix.c
parent4e9da1551b2fea579e3e96b7fb80b32e101c268d (diff)
downloadgcc-76b88c5fc9930734f4d3496b9100862f62311ce5.zip
gcc-76b88c5fc9930734f4d3496b9100862f62311ce5.tar.gz
gcc-76b88c5fc9930734f4d3496b9100862f62311ce5.tar.bz2
re PR libfortran/67527 (io.h sanitizer complains on 1 << 31)
PR libfortran/67527 PR libfortran/67535 PR libfortran/67536 * io/io.h: Use unsigned values for 31-bit left shifts. * io/unix.c (buf_read): Do not call memcpy() with NULL pointer arg. * io/write.c (nml_write_obj): Likewise. From-SVN: r227705
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r--libgfortran/io/unix.c8
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