public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, libfortran] Fix PR 80365, undefined memcpy
@ 2017-07-23 19:23 Thomas Koenig
  2017-07-24 10:09 ` Janne Blomqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Koenig @ 2017-07-23 19:23 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 449 bytes --]

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.

[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 349 bytes --]

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;
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch, libfortran] Fix PR 80365, undefined memcpy
  2017-07-23 19:23 [patch, libfortran] Fix PR 80365, undefined memcpy Thomas Koenig
@ 2017-07-24 10:09 ` Janne Blomqvist
  2017-07-24 11:13   ` Thomas Koenig
  0 siblings, 1 reply; 4+ messages in thread
From: Janne Blomqvist @ 2017-07-24 10:09 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Sun, Jul 23, 2017 at 10:23 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> 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?

Good catch, Ok.


-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch, libfortran] Fix PR 80365, undefined memcpy
  2017-07-24 10:09 ` Janne Blomqvist
@ 2017-07-24 11:13   ` Thomas Koenig
  2017-07-28 19:22     ` Janne Blomqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Koenig @ 2017-07-24 11:13 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: fortran, gcc-patches

Hi Janne,

> On Sun, Jul 23, 2017 at 10:23 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
>> 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?
> 
> Good catch, Ok.


Committed, thanks for the review.

What is the opinion on backporting?  We should avoid undefined
behavior in the library, I think, so I am leanding towards
doing it.

Regards

	Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch, libfortran] Fix PR 80365, undefined memcpy
  2017-07-24 11:13   ` Thomas Koenig
@ 2017-07-28 19:22     ` Janne Blomqvist
  0 siblings, 0 replies; 4+ messages in thread
From: Janne Blomqvist @ 2017-07-28 19:22 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Mon, Jul 24, 2017 at 2:12 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hi Janne,
>
>> On Sun, Jul 23, 2017 at 10:23 PM, Thomas Koenig <tkoenig@netcologne.de>
>> wrote:
>>>
>>> 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?
>>
>>
>> Good catch, Ok.
>
>
>
> Committed, thanks for the review.
>
> What is the opinion on backporting?  We should avoid undefined
> behavior in the library, I think, so I am leanding towards
> doing it.
>
> Regards
>
>         Thomas
>

Sure, go ahead. I can't see how the patch would cause any bugs (knock
knock...), so it seems quite safe.

BTW, there might be a similar issue in buf_read()?


-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-28 19:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-23 19:23 [patch, libfortran] Fix PR 80365, undefined memcpy Thomas Koenig
2017-07-24 10:09 ` Janne Blomqvist
2017-07-24 11:13   ` Thomas Koenig
2017-07-28 19:22     ` Janne Blomqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).