[Bug other/85778] unexpected results with -O2, wrong code?

2018-05-15 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #5 from Martin Sebor  ---
(In reply to Scott Emmons from comment #4)
> > glibc has stat annotated with nonnull(1, 2)
> 
> 1. Can you provide a reference to this code? This is helpful so that other
> people running into this (and it *will* happen, this ancient code no longer
> runs correctly). Thank you.

stat() is a POSIX function and (similarly to C) POSIX specifies (in 2.1.1 Use
and Implementation of Functions of XSH) that:

If an argument to a function has an invalid value (such as a value outside the
domain of the function, or a pointer outside the address space of the program,
or a null pointer), the behavior is undefined.

A link to the section in the latest spec:
pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_01_01

[Bug other/85778] unexpected results with -O2, wrong code?

2018-05-15 Thread sesail999 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778

--- Comment #4 from Scott Emmons  ---
> glibc has stat annotated with nonnull(1, 2)

1. Can you provide a reference to this code? This is helpful so that other
people running into this (and it *will* happen, this ancient code no longer
runs correctly). Thank you.

2. The manpage for stat(2) should be updated to reflect that calling stat()
with a NULL pathname will result in unpredictable behavior.

3. I'll create a pull request against cronolog and work with Debian/Ubuntu to
at least get it fixed in those distributions.

[Bug other/85778] unexpected results with -O2, wrong code?

2018-05-15 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
Version|unknown |8.1.0
 Resolution|--- |INVALID

--- Comment #3 from Richard Biener  ---
glibc has stat annotated with nonnull(1, 2)

[Bug other/85778] unexpected results with -O2, wrong code?

2018-05-14 Thread sesail999 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778

Scott E.  changed:

   What|Removed |Added

 CC||sesail999 at gmail dot com

--- Comment #2 from Scott E.  ---
Just to add a few more details, I discovered this via "cronolog", which does
this pattern of stat() with a null pathname. Not that it makes the code
correct, and it could easily be guarded against, however this code has been
working fine since 2001 [1].

There's a few more details in the downstream bug report [2].

[1]
https://github.com/fordmason/cronolog/blame/83f9e99d6bd5cb8f5cc06723f4d79d1265582340/src/cronoutils.c#L250
[2] https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1770676

[Bug other/85778] unexpected results with -O2, wrong code?

2018-05-14 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778

--- Comment #1 from Andrew Pinski  ---
It depends on if glibc is adding the nonnull attribute to stat or is it GCC. 
Also what does the C (and POSIX) standard says about a null pointer being
passed as the string to stat.