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

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).