This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libfortran] Fix PR 80365, undefined memcpy
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 23 Jul 2017 21:23:35 +0200
- Subject: [patch, libfortran] Fix PR 80365, undefined memcpy
- Authentication-results: sourceware.org; auth=none
Hello world,
the attached test cases fixes a problematic invocation of
memcpy where src=NULL and n=0 by simply doing nothing
in the surrounding function if there is nothing to be done.
No test case, because this only shows up with a sanitized
libgfortran or under a debugger.
OK for trunk?
Regards
Thomas
2017-07-23 Thomas Koenig <tkoenig@gcc.gnu.org>
* io/unix.c (buf_write): Return early if there is
nothing to write.
Index: io/unix.c
===================================================================
--- io/unix.c (Revision 249936)
+++ io/unix.c (Arbeitskopie)
@@ -582,6 +582,9 @@
static ssize_t
buf_write (unix_stream *s, const void *buf, ssize_t nbyte)
{
+ if (nbyte == 0)
+ return 0;
+
if (s->ndirty == 0)
s->buffer_offset = s->logical_offset;