public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egallager at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/78155] missing warning on invalid usage of functions/macros from <ctype.h> (isalpha et al.)
Date: Wed, 08 Jun 2022 17:39:23 +0000	[thread overview]
Message-ID: <bug-78155-4-zxwHGgKgIy@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-78155-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78155

--- Comment #8 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #4)
> I don't really see what existing warning this might fall under, except
> perhaps -Wchar-subscripts because isalpha and friend use the argument as an
> index into an array of 257 characters, but that seems like a stretch.
> 
> I think maybe adding a more general warning option, say something like
> -Wargument-range, and using it to diagnose all such problems, might be the
> way to go.  To generalize the solution I would even consider adding a new
> function attribute, let's call it range, to specify the range of valid
> values of a function argument.  Then isalpha (or any other such function)
> could be declared like so:
> 
>   __attribute__ ((range (/* position = */1, -1, UCHAR_MAX)))
>   int isalpha (int);
> 
> GCC would then check every call to the function to see if its argument is in
> the expected range and, if not, issue a warning.  The attribute could even
> be applied multiple times to specify disjoint ranges.  Position zero could
> denote the return value so that toupper could be declared like so
> 
>   __attribute__ ((range (/* returns = */ 0, -1, UCHAR_MAX),
>                   range (/* position = */ 1, -1, UCHAR_MAX)))
>   int toupper (int);

There's been an attempt to add an attribute like this recently on the mailing
lists: https://gcc.gnu.org/pipermail/gcc/2022-June/238819.html

      parent reply	other threads:[~2022-06-08 17:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-78155-4@http.gcc.gnu.org/bugzilla/>
2020-05-04 11:51 ` [Bug c/78155] missing warning on invalid isalpha et al bruno at clisp dot org
2022-04-28 11:57 ` [Bug c/78155] missing warning on invalid usage of functions/macros from <ctype.h> (isalpha et al.) egallager at gcc dot gnu.org
2022-06-08 17:39 ` egallager at gcc dot gnu.org [this message]

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=bug-78155-4-zxwHGgKgIy@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).