Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Martin Uecker via Gcc
Am Freitag, dem 24.02.2023 um 10:01 -0600 schrieb Serge E. Hallyn: > On Fri, Feb 24, 2023 at 09:36:45AM +0100, Martin Uecker wrote: > > Am Donnerstag, dem 23.02.2023 um 19:21 -0600 schrieb Serge E. Hallyn: ... > > > > Yes, but one comment about terminology:. The C standard > > differentiates betw

Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Serge E. Hallyn
On Fri, Feb 24, 2023 at 02:42:32AM +0100, Alex Colomar wrote: > Hi Serge, Martin, > > On 2/24/23 02:21, Serge E. Hallyn wrote: > > > Does all this imply that the following is well defined behavior (and shall > > > print what one would expect)? > > > > > >free(p); > > > > > >(void) &p; /

Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Serge E. Hallyn
On Fri, Feb 24, 2023 at 09:36:45AM +0100, Martin Uecker wrote: > Am Donnerstag, dem 23.02.2023 um 19:21 -0600 schrieb Serge E. Hallyn: > > On Fri, Feb 24, 2023 at 01:02:54AM +0100, Alex Colomar wrote: > > > Hi Martin, > > > > > > On 2/23/23 20:57, Martin Uecker wrote: > > > > Am Donnerstag, dem 23

Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Martin Uecker via Gcc
Am Freitag, dem 24.02.2023 um 03:01 + schrieb Peter Lafreniere: ... > > > Maybe it could do an exception for printing, that is, reading a pointer > > is not a problem in itself, a long as you don't compare it, but I'm not > > such an expert about this. > > One last thought: with the above st

Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Martin Uecker via Gcc
Am Freitag, dem 24.02.2023 um 02:42 +0100 schrieb Alex Colomar: > Hi Serge, Martin, > > On 2/24/23 02:21, Serge E. Hallyn wrote: > > > Does all this imply that the following is well defined behavior (and shall > > > print what one would expect)? > > > > > >    free(p); > > > > > >    (void) &p;

Re: Missed warning (-Wuse-after-free)

2023-02-24 Thread Martin Uecker via Gcc
Am Donnerstag, dem 23.02.2023 um 19:21 -0600 schrieb Serge E. Hallyn: > On Fri, Feb 24, 2023 at 01:02:54AM +0100, Alex Colomar wrote: > > Hi Martin, > > > > On 2/23/23 20:57, Martin Uecker wrote: > > > Am Donnerstag, dem 23.02.2023 um 20:23 +0100 schrieb Alex Colomar: > > > > Hi Martin, > > > > >

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Peter Lafreniere via Gcc
If I may add my thoughts here, On Thursday, February 23rd, 2023 at 20:42, Alex Colomar wrote: > I'll try to show why this feels weird to me (even in C89): > > > alx@dell7760:~/tmp$ cat pointers.c > #include > > #include > > > > int > main(void) > { > char *p, *q; > > p = malloc(42); > if (p == N

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Alex Colomar via Gcc
Hi Serge, Martin, On 2/24/23 02:21, Serge E. Hallyn wrote: Does all this imply that the following is well defined behavior (and shall print what one would expect)? free(p); (void) &p; // take the address // or maybe we should (void) memcmp(&p, &p, sizeof(p)); ? printf("%p\n", p);

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Serge E. Hallyn
On Fri, Feb 24, 2023 at 01:02:54AM +0100, Alex Colomar wrote: > Hi Martin, > > On 2/23/23 20:57, Martin Uecker wrote: > > Am Donnerstag, dem 23.02.2023 um 20:23 +0100 schrieb Alex Colomar: > > > Hi Martin, > > > > > > On 2/17/23 14:48, Martin Uecker wrote: > > > > > This new wording doesn't even

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Alex Colomar via Gcc
Hi Martin, On 2/23/23 20:57, Martin Uecker wrote: Am Donnerstag, dem 23.02.2023 um 20:23 +0100 schrieb Alex Colomar: Hi Martin, On 2/17/23 14:48, Martin Uecker wrote: This new wording doesn't even allow one to use memcmp(3); just reading the pointer value, however you do it, is UB. memcmp w

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Martin Uecker via Gcc
Am Donnerstag, dem 23.02.2023 um 20:23 +0100 schrieb Alex Colomar: > Hi Martin, > > On 2/17/23 14:48, Martin Uecker wrote: > > > This new wording doesn't even allow one to use memcmp(3); > > > just reading the pointer value, however you do it, is UB. > > > > memcmp would not use the pointer value

Re: Missed warning (-Wuse-after-free)

2023-02-23 Thread Alex Colomar via Gcc
Hi Martin, On 2/17/23 14:48, Martin Uecker wrote: This new wording doesn't even allow one to use memcmp(3); just reading the pointer value, however you do it, is UB. memcmp would not use the pointer value but work on the representation bytes and is still allowed. Hmm, interesting. It's rath

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Jonathan Wakely via Gcc
On Fri, 17 Feb 2023, 12:53 Siddhesh Poyarekar, wrote: > On 2023-02-17 06:24, Jonathan Wakely wrote: > > Please be aware that in C++ it's implementation-defined, not undefined. > > > > That means that an implementation without trap representations for > > pointers can choose to make it behave just

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Siddhesh Poyarekar
On 2023-02-17 09:01, Mark Wielaard wrote: The reason people might not know about it, is that the documentation is somewhat unclear. -Wall says it already includes -Wuse-after-free=3: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wall Yeah I posted a patch to fix it only a few mi

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Mark Wielaard
On Fri, 2023-02-17 at 08:38 -0500, Siddhesh Poyarekar wrote: > On 2023-02-17 06:22, Alejandro Colomar wrote: > > Hi Siddhesh, > > > > On 2/17/23 04:48, Siddhesh Poyarekar wrote: > > > On 2023-02-16 10:15, David Malcolm via Gcc wrote: > > > > I'm not convinced that it's useful to the end-user to wa

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Siddhesh Poyarekar
On 2023-02-17 08:44, David Malcolm wrote: This is possibly a silly question, but what *are* these safe alternatives? [1] How does one test to see if an object has been reallocated? Oops sorry, I snipped off that part when pasting from the man page. Typically such conditionals are used to updat

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Martin Uecker via Gcc
Am Freitag, dem 17.02.2023 um 12:35 +0100 schrieb Alejandro Colomar: > Hi Martin, > > On 2/17/23 09:12, Martin Uecker wrote: > > Am Freitag, dem 17.02.2023 um 02:04 +0100 schrieb Alejandro Colomar > > > > > > > > > > [...] > > > > > > > > > > > I'm not convinced that it's useful to the end-us

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread David Malcolm via Gcc
On Thu, 2023-02-16 at 22:48 -0500, Siddhesh Poyarekar wrote: > On 2023-02-16 10:15, David Malcolm via Gcc wrote: > > I'm not convinced that it's useful to the end-user to warn about > > the > > "use of q itself" case. > > FWIW, -Wuse-after-free=3 already should do this: > > At level 3, the warnin

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Siddhesh Poyarekar
On 2023-02-17 06:22, Alejandro Colomar wrote: Hi Siddhesh, On 2/17/23 04:48, Siddhesh Poyarekar wrote: On 2023-02-16 10:15, David Malcolm via Gcc wrote: I'm not convinced that it's useful to the end-user to warn about the "use of q itself" case. FWIW, -Wuse-after-free=3 already should do thi

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Andreas Schwab
On Feb 17 2023, Alejandro Colomar via Gcc wrote: > C2x (N3054 is the latest I know): > > If a pointer value is used in an evaluation after > the object the pointer points to (or just past) > reaches the end of its lifetime, > the behavior is undefined. >

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Siddhesh Poyarekar
On 2023-02-17 06:24, Jonathan Wakely wrote: Please be aware that in C++ it's implementation-defined, not undefined. That means that an implementation without trap representations for pointers can choose to make it behave just like using (uintptr_t)p. https://cplusplus.github.io/CWG/issues/143

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Jonathan Wakely via Gcc
On Fri, 17 Feb 2023, 11:43 Alejandro Colomar, wrote: > Hi Jonathan, > > On 2/17/23 12:24, Jonathan Wakely wrote: > > Please be aware that in C++ it's implementation-defined, not undefined. > > > > That means that an implementation without trap representations for > pointers > > can choose to make

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Alejandro Colomar via Gcc
Hi Jonathan, On 2/17/23 12:24, Jonathan Wakely wrote: > Please be aware that in C++ it's implementation-defined, not undefined. > > That means that an implementation without trap representations for pointers > can choose to make it behave just like using (uintptr_t)p. (uintptr_t)p is defined (I

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Alejandro Colomar via Gcc
Hi Martin, On 2/17/23 09:12, Martin Uecker wrote: > Am Freitag, dem 17.02.2023 um 02:04 +0100 schrieb Alejandro Colomar > > >> >> [...] >> >>> >>> I'm not convinced that it's useful to the end-user to warn about >>> the >>> "use of q itself" case. >> >> I didn't quote the standard because I coul

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Jonathan Wakely via Gcc
On Fri, 17 Feb 2023, 03:49 Siddhesh Poyarekar, wrote: > On 2023-02-16 10:15, David Malcolm via Gcc wrote: > > I'm not convinced that it's useful to the end-user to warn about the > > "use of q itself" case. > > FWIW, -Wuse-after-free=3 already should do this: > > At level 3, the warning also diag

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Alejandro Colomar via Gcc
Hi Siddhesh, On 2/17/23 04:48, Siddhesh Poyarekar wrote: > On 2023-02-16 10:15, David Malcolm via Gcc wrote: >> I'm not convinced that it's useful to the end-user to warn about the >> "use of q itself" case. > > FWIW, -Wuse-after-free=3 already should do this: Thanks! It works. I would have ex

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Yann Droneaud
Hi, Le 16/02/2023 à 15:35, Alejandro Colomar via Gcc a écrit : Hi! I was preparing an example program of a use-after-realloc bug, when I found that GCC doesn't warn in a case where it should. alx@debian:~/tmp$ cat realloc.c #include #include #include #include #include static inline char

Re: Missed warning (-Wuse-after-free)

2023-02-17 Thread Martin Uecker via Gcc
Am Freitag, dem 17.02.2023 um 02:04 +0100 schrieb Alejandro Colomar > > [...] > > > > > I'm not convinced that it's useful to the end-user to warn about > > the > > "use of q itself" case. > > I didn't quote the standard because I couldn't find it.  I was > searching in C11, > and it seems th

Re: Missed warning (-Wuse-after-free)

2023-02-16 Thread Siddhesh Poyarekar
On 2023-02-16 10:15, David Malcolm via Gcc wrote: I'm not convinced that it's useful to the end-user to warn about the "use of q itself" case. FWIW, -Wuse-after-free=3 already should do this: At level 3, the warning also diagnoses uses of indeterminate pointers in equality expressions. All u

Re: Missed warning (-Wuse-after-free)

2023-02-16 Thread Sam James via Gcc
> On 17 Feb 2023, at 01:05, Alejandro Colomar via Gcc wrote: > > On 2/17/23 02:04, Alejandro Colomar wrote: >> [CC: Added those who contributed to the discussion in linux-man@, >> and also the authors of N2861 for C2x] > > [...] > >> >> There was a discussion in linux-man@ some years ago

Re: Missed warning (-Wuse-after-free)

2023-02-16 Thread Alejandro Colomar via Gcc
On 2/17/23 02:04, Alejandro Colomar wrote: > [CC: Added those who contributed to the discussion in linux-man@, > and also the authors of N2861 for C2x] [...] > > There was a discussion in linux-man@ some years ago, which now I realize it > didn't end up being applied (I thought we had appli

Re: Missed warning (-Wuse-after-free)

2023-02-16 Thread Alejandro Colomar via Gcc
[CC: Added those who contributed to the discussion in linux-man@, and also the authors of N2861 for C2x] Hi David, On 2/16/23 16:15, David Malcolm wrote: > On Thu, 2023-02-16 at 15:35 +0100, Alejandro Colomar via Gcc wrote: >> Hi! >> >> I was preparing an example program of a use-after-reall

Re: Missed warning (-Wuse-after-free)

2023-02-16 Thread David Malcolm via Gcc
On Thu, 2023-02-16 at 15:35 +0100, Alejandro Colomar via Gcc wrote: > Hi! > > I was preparing an example program of a use-after-realloc bug, > when I found that GCC doesn't warn in a case where it should. > > > alx@debian:~/tmp$ cat realloc.c > #include > #include > #include > #include > #in

Missed warning (-Wuse-after-free)

2023-02-16 Thread Alejandro Colomar via Gcc
Hi! I was preparing an example program of a use-after-realloc bug, when I found that GCC doesn't warn in a case where it should. alx@debian:~/tmp$ cat realloc.c #include #include #include #include #include static inline char * xstrdup(const char *s) { char *p; p = strdup(