public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile@starynkevitch.net>
To: gcc@gcc.gnu.org, mirimnan017@gmail.com
Subject: GSoC: Working on the static analyzer
Date: Mon, 14 Feb 2022 13:59:54 +0100	[thread overview]
Message-ID: <8e40d86b-8d93-cf29-e53e-a634b1fe2129@starynkevitch.net> (raw)
In-Reply-To: <mailman.6588.1644793069.2100866.gcc@gcc.gnu.org>

Hello,


Mir Immad asked:

> Should the analyzer warn for code like this "when open fails" (like strchr
> does when  'strchr' returns NULL)
>
> int fd = open("NOFILE", O_RDONLY);
> write(fd, "a", 1);
>
> because of the bad file descriptor.
> unless it is written like this:
> if (!errno)
>    write(fd, "a", 1);

My opinion is yes, in most cases. BTW, the write should fail for a 
read-only file descriptor.


A case (on Linux) where a check is probably not needed: isint 
fd=open("/proc/self/exe", O_RDONLY); or int fd=open ("/dev/random", 
O_RDONLY); done *near the beginning* of main. There are only 
pathological cases where they won't succeed. I suspect that except for 
very critical executable, testing such failures is practically useless.

And your analyzer might start from https://github.com/bstarynk/bismon/ 
or use https://frama-c.com/ <https://frama-c.com/>



PS. My pet project is http://refpersys.org/ (Soon generating code 
compiled by GCC). It is not GCC related.

-- 
Basile Starynkevitch<basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/

       reply	other threads:[~2022-02-14 12:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6588.1644793069.2100866.gcc@gcc.gnu.org>
2022-02-14 12:59 ` Basile Starynkevitch [this message]
2022-02-14 13:12   ` Basile Starynkevitch
2022-01-11  5:33 Mir Immad
2022-01-11 13:39 ` David Malcolm
2022-01-14 16:45   ` Mir Immad
2022-01-17  0:11     ` David Malcolm
     [not found]       ` <CAE1-7ozOGbp-sypHeWxJpoLWzNbqYtWrrsnhLK9RdhYrLe6z1w@mail.gmail.com>
2022-01-23 20:11         ` Mir Immad
2022-01-24 14:19           ` Ankur Saini
2022-01-26 14:31             ` David Malcolm
2022-01-26 14:26           ` David Malcolm
2022-01-29 14:52             ` Mir Immad
2022-01-29 17:39               ` David Malcolm
2022-02-01 14:58                 ` Mir Immad
2022-02-13 15:46                   ` Mir Immad
2022-02-13 22:57                     ` David Malcolm
2022-02-13 23:05                       ` David Malcolm
2022-04-04 16:16                         ` Mir Immad
2022-04-08 18:19                           ` 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=8e40d86b-8d93-cf29-e53e-a634b1fe2129@starynkevitch.net \
    --to=basile@starynkevitch.net \
    --cc=gcc@gcc.gnu.org \
    --cc=mirimnan017@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).