public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/113329] New: analyzer: False positive analyzer-fd-use-without-check with dup2()
@ 2024-01-11 8:33 buczek at molgen dot mpg.de
2024-04-28 18:56 ` [Bug analyzer/113329] " alan.coopersmith at oracle dot com
2024-04-28 18:56 ` alan.coopersmith at oracle dot com
0 siblings, 2 replies; 3+ messages in thread
From: buczek at molgen dot mpg.de @ 2024-01-11 8:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113329
Bug ID: 113329
Summary: analyzer: False positive analyzer-fd-use-without-check
with dup2()
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: buczek at molgen dot mpg.de
Target Milestone: ---
Using a closed file descriptor as the second argument of dup2() is a valid
usage. It makes sense, because the implicit close of dup2() doesn't return
close errors to the caller, so an explicit close might be preferred.
** Code:
#include <unistd.h>
void f(int oldfd, int newfd) {
close(newfd);
dup2(oldfd, newfd);
}
** Result:
<source>: In function 'f':
<source>:4:5: warning: 'dup2' on possibly invalid file descriptor 'newfd'
[-Wanalyzer-fd-use-without-check]
4 | dup2(oldfd, newfd);
| ^~~~~~~~~~~~~~~~~~
'f': events 1-2
|
| 3 | close(newfd);
| | ^~~~~~~~~~~~
| | |
| | (1) closed here
| 4 | dup2(oldfd, newfd);
| | ~~~~~~~~~~~~~~~~~~
| | |
| | (2) 'newfd' could be invalid
|
Compiler returned: 0
https://gcc.godbolt.org/z/8zac19e15
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/113329] analyzer: False positive analyzer-fd-use-without-check with dup2()
2024-01-11 8:33 [Bug analyzer/113329] New: analyzer: False positive analyzer-fd-use-without-check with dup2() buczek at molgen dot mpg.de
@ 2024-04-28 18:56 ` alan.coopersmith at oracle dot com
2024-04-28 18:56 ` alan.coopersmith at oracle dot com
1 sibling, 0 replies; 3+ messages in thread
From: alan.coopersmith at oracle dot com @ 2024-04-28 18:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113329
Alan Coopersmith <alan.coopersmith at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |alan.coopersmith at oracle dot com
--- Comment #1 from Alan Coopersmith <alan.coopersmith at oracle dot com> ---
Created attachment 58057
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58057&action=edit
dup2.c test case
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/113329] analyzer: False positive analyzer-fd-use-without-check with dup2()
2024-01-11 8:33 [Bug analyzer/113329] New: analyzer: False positive analyzer-fd-use-without-check with dup2() buczek at molgen dot mpg.de
2024-04-28 18:56 ` [Bug analyzer/113329] " alan.coopersmith at oracle dot com
@ 2024-04-28 18:56 ` alan.coopersmith at oracle dot com
1 sibling, 0 replies; 3+ messages in thread
From: alan.coopersmith at oracle dot com @ 2024-04-28 18:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113329
--- Comment #2 from Alan Coopersmith <alan.coopersmith at oracle dot com> ---
I've hit this as well with gcc 13.2 when building xfs with -fanalyzer.
I extracted this test case from
https://gitlab.freedesktop.org/xorg/app/xfs/-/blob/master/os/daemon.c
and when built with "gcc -fanalyzer -c dup2.c" it reports:
dup2.c: In function ‘DetachStdio’:
dup2.c:23:13: warning: ‘dup2’ on possibly invalid file descriptor ‘0’
[-Wanalyzer-fd-use-without-check]
23 | if (dup2(nullfd, 0) == -1) {
| ^~~~~~~~~~~~~~~
‘DetachStdio’: events 1-6
|
| 10 | close (0);
| | ^~~~~~~~~
| | |
| | (1) closed here
|......
| 18 | if (nullfd == -1) {
| | ~
| | |
| | (2) following ‘false’ branch (when ‘nullfd != -1’)...
|......
| 22 | if (nullfd != 0) {
| | ~
| | |
| | (3) ...to here
| | (4) following ‘true’ branch (when ‘nullfd != 0’)...
| 23 | if (dup2(nullfd, 0) == -1) {
| | ~~~~~~~~~~~~~~~
| | |
| | (5) ...to here
| | (6) ‘0’ could be invalid
|
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-28 18:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 8:33 [Bug analyzer/113329] New: analyzer: False positive analyzer-fd-use-without-check with dup2() buczek at molgen dot mpg.de
2024-04-28 18:56 ` [Bug analyzer/113329] " alan.coopersmith at oracle dot com
2024-04-28 18:56 ` alan.coopersmith at oracle dot com
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).