public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99950] New: Option -Wchar-subscripts leads to wrong fixes
@ 2021-04-07  6:46 roland.illig at gmx dot de
  2021-04-07  7:26 ` [Bug c/99950] " egallager at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: roland.illig at gmx dot de @ 2021-04-07  6:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99950
           Summary: Option -Wchar-subscripts leads to wrong fixes
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland.illig at gmx dot de
  Target Milestone: ---

When code calls the functions from <ctype.h> with an expression of type 'char',
GCC and Clang warn:

> array subscript has type char

Since the function prototypes expect an 'int', inexperienced programmers cast
the argument to 'int', which silences the warning:

https://github.com/search?q=%22isspace+int%22&type=code

More experienced programmers who heard something about 'unsigned' cast the
argument to 'unsigned int', which silences the warning as well:

https://github.com/search?q=%22isspace+unsigned+int%22&type=code

To get these programmers to fix their code properly, GCC should provide more
guidance in this area.  As a quick prototype I implemented a check for these
wrong "fixes" in NetBSD's lint, which results in warnings like these:

warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char',
not to 'int' [342]

The implementation is here, including a test:

https://github.com/NetBSD/src/blob/fdd2c09ca474/usr.bin/xlint/lint1/ckctype.c
https://github.com/NetBSD/src/blob/fdd2c09ca474/tests/usr.bin/xlint/lint1/msg_341.c
https://github.com/NetBSD/src/blob/fdd2c09ca474/tests/usr.bin/xlint/lint1/msg_341.exp

Maybe GCC can implement a similar check to prevent these wrong fixes in the
future.

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

end of thread, other threads:[~2022-04-28 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07  6:46 [Bug c/99950] New: Option -Wchar-subscripts leads to wrong fixes roland.illig at gmx dot de
2021-04-07  7:26 ` [Bug c/99950] " egallager at gcc dot gnu.org
2021-04-07 15:47 ` msebor at gcc dot gnu.org
2022-04-28 11:59 ` [Bug c/99950] Option -Wchar-subscripts leads to wrong fixes when used with functions from <ctype.h> 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).