Launchpad has imported 6 comments from the remote bug at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85778.
If you reply to an imported comment from within Launchpad, your comment will be sent to the remote bug automatically. Read more about Launchpad's inter-bugtracker facilities at https://help.launchpad.net/InterBugTracking. ------------------------------------------------------------------------ On 2018-05-14T18:19:18+00:00 Doko-v wrote: seen with GCC 5 and all newer version. Is this wrong-code? $ cat testcase.c #include <stdio.h> #include <sys/stat.h> #define PRINT \ if (foo == NULL) \ printf("foo in func() is %p, NULL (expected)\n", foo); \ else \ printf("foo in func() is %p, not NULL (NOT EXPECTED!)\n", foo); void func(const char *foo) { struct stat stat_buf; PRINT; stat(foo, &stat_buf); PRINT; } int main() { const char *foo = NULL; struct stat stat_buf; func(NULL); PRINT; stat(foo, &stat_buf); PRINT; return 0; } $ gcc -O0 testcase.c && ./a.out foo in func() is (nil), NULL (expected) foo in func() is (nil), NULL (expected) foo in func() is (nil), NULL (expected) foo in func() is (nil), NULL (expected) $ gcc -O2 testcase.c && ./a.out foo in func() is (nil), NULL (expected) foo in func() is (nil), not NULL (NOT EXPECTED!) foo in func() is (nil), NULL (expected) foo in func() is (nil), NULL (expected) Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/5 ------------------------------------------------------------------------ On 2018-05-14T18:27:19+00:00 Pinskia wrote: 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. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/6 ------------------------------------------------------------------------ On 2018-05-14T23:28:08+00:00 Sesail999 wrote: 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 Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/7 ------------------------------------------------------------------------ On 2018-05-15T07:32:15+00:00 Rguenth wrote: glibc has stat annotated with nonnull(1, 2) Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/8 ------------------------------------------------------------------------ On 2018-05-15T15:44:58+00:00 Sesail999 wrote: > 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. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/9 ------------------------------------------------------------------------ On 2018-05-15T20:17:43+00:00 Msebor wrote: (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 Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1770676/comments/13 -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/1770676 Title: cronolog doesn't update links due to stat() on NULL pathname To manage notifications about this bug go to: https://bugs.launchpad.net/gcc/+bug/1770676/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
