public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Gavin Ray <ray.gavin97@gmail.com>
Cc: David Malcolm <dmalcolm@redhat.com>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: -fanalyzer: Questions on C vs CPP + use of GCC attr's like malloc()/access()
Date: Sat, 26 Nov 2022 14:09:26 +0000	[thread overview]
Message-ID: <CAH6eHdT+QrN_w55tDqN2tjKhvh72Mo2LAhKLdkckea7yRU+iWw@mail.gmail.com> (raw)
In-Reply-To: <CAFtvWZMKinUBAF2VR1f+y-DdnvxsHq2yi3SOeVj+_LpJKhG5Cg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1049 bytes --]

On Fri, 25 Nov 2022, 18:55 Gavin Ray via Gcc, <gcc@gcc.gnu.org> wrote:

>
> On a related note, the "fd" analyzers warn: "fd may not be valid" but don't
> clarify what "valid" means.
>

A valid file descriptor is one that was returned by the C library and
refers to an open file. That's not something GCC defines.


> I found the DOT diagrams in the analyzer source and it turns out that the
> key is
> to check "if (fd >= 0)".


The point is that the OS functions that return a new file descriptor return
a negative value on error, so all valid file descriptors are non-negative.
But not all non-negative integers are valid file descriptors.

You should check for errors when calling open, dup2, socket etc. so you
know whether it succeeded.


Maybe this could be added to the "fd" analyzer
> warnings/info, too?
>

I don't think that's a good idea unless word carefully, it's not as simple
as "test if it's non-negative". You should check for errors when using OS
APIs, but that's always true, it's not difficult to the analyzer output.



>
>
>
>

  reply	other threads:[~2022-11-26 14:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  1:49 Gavin Ray
2022-11-25 17:33 ` David Malcolm
2022-11-25 18:55   ` Gavin Ray
2022-11-26 14:09     ` Jonathan Wakely [this message]
2022-11-26 15:48       ` Gavin Ray
2022-11-26 17:47         ` Jonathan Wakely
2022-11-26 18:51           ` David Malcolm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdT+QrN_w55tDqN2tjKhvh72Mo2LAhKLdkckea7yRU+iWw@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=ray.gavin97@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).