public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/78155] missing warning on invalid isalpha et al.
       [not found] <bug-78155-4@http.gcc.gnu.org/bugzilla/>
@ 2020-05-04 11:51 ` 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
  2 siblings, 0 replies; 3+ messages in thread
From: bruno at clisp dot org @ 2020-05-04 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bruno at clisp dot org

--- Comment #6 from Bruno Haible <bruno at clisp dot org> ---
Created attachment 48440
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48440&action=edit
Test case

Another test case is the attached program, alpha.c. When run on glibc systems
on x86, x86_64, and other CPUs (not powerpc), it sign-extends the 'char'
argument; so the character 'ÿ' (in ISO-8859-1 encoding) becomes EOF, and the
<ctype.h> function returns 0.

$ LC_ALL=de_DE.ISO-8859-1 xterm
$ ./a.out ÿ
not alphabetic

The corrected program (with a cast to 'unsigned char' in the isalpha()
argument) behaves as expected:

$ LC_ALL=de_DE.ISO-8859-1 xterm
$ ./a.out ÿ
alphabetic

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/78155] missing warning on invalid usage of functions/macros from <ctype.h> (isalpha et al.)
       [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 ` egallager at gcc dot gnu.org
  2022-06-08 17:39 ` egallager at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-04-28 11:57 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|missing warning on invalid  |missing warning on invalid
                   |isalpha et al.              |usage of functions/macros
                   |                            |from <ctype.h> (isalpha et
                   |                            |al.)

--- Comment #7 from Eric Gallager <egallager at gcc dot gnu.org> ---
retitling to help me find it more easily again later

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/78155] missing warning on invalid usage of functions/macros from <ctype.h> (isalpha et al.)
       [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
  2 siblings, 0 replies; 3+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-06-08 17:39 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-08 17:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 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).