Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: [PATCH] pre-process: fix a compiler array subscript type warning
Date: Fri, 5 Jun 2020 22:29:24 +0100	[thread overview]
Message-ID: <fbb9ba2b-14fa-c6e1-a730-80d35547ea52@ramsayjones.plus.com> (raw)


On cygwin, the <ctype.h> header is written in such a way as to cause
a gcc compiler warning if a plain 'char' is passed to the character
classification macros (in this case isdigit). The result is defined
only if the parameter is representable as an unsigned char, or if it
is EOF.

When passing a 'char' type argument to isdigit(), the compiler warns
like so:

    CC      pre-process.o
  In file included from pre-process.c:33:
  pre-process.c: In function ‘predefine’:
  pre-process.c:1429:18: warning: array subscript has type ‘char’ [-Wchar-subscripts]
   1429 |   if (isdigit(buf[0])) {
        |               ~~~^~~

In order to suppress the warning, cast the argument of isdigit() to
an 'unsigned char' type.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---

Hi Luc,

Having not done so in a while, last night I updated my cygwin
installation. This resulted in updates to the versions of the
libc/headers/gcc, among other things. (eg. gcc is now v9.3.0).

This patch fixes the new compiler warning that results!

ATB,
Ramsay Jones

 pre-process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pre-process.c b/pre-process.c
index c8725dc8..d96035e2 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -1426,7 +1426,7 @@ void predefine(const char *name, int weak, const char *fmt, ...)
 		va_end(ap);
 
 		value = __alloc_token(0);
-		if (isdigit(buf[0])) {
+		if (isdigit((unsigned char)buf[0])) {
 			token_type(value) = TOKEN_NUMBER;
 			value->number = xstrdup(buf);
 		} else {
-- 
2.27.0

             reply	other threads:[~2020-06-05 21:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 21:29 Ramsay Jones [this message]
2020-06-05 23:09 ` [PATCH] pre-process: fix a compiler array subscript type warning Luc Van Oostenryck

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=fbb9ba2b-14fa-c6e1-a730-80d35547ea52@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@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