git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Junio C Hamano <gitster@pobox.com>,
	GIT Mailing-list <git@vger.kernel.org>
Subject: [PATCH] xemit.c: fix a [-Wchar-subscripts] compiler warning
Date: Thu, 26 May 2016 00:06:27 +0100	[thread overview]
Message-ID: <57462FF3.4010705@ramsayjones.plus.com> (raw)


While compiling on cygwin (x86_64), gcc complains thus:

      CC xdiff/xemit.o
  xdiff/xemit.c: In function ‘is_empty_rec’:
  xdiff/xemit.c:163:2: warning: array subscript has type ‘char’ [-Wchar-subscripts]
    while (len > 0 && isspace(*rec)) {
    ^

A comment in the <ctype.h> header reads, in part, like so:

   These macros are intentionally written in a manner that will trigger
   a gcc -Wall warning if the user mistakenly passes a 'char' instead
   of an int containing an 'unsigned char'.

In order to suppress the warning, cast the 'char *' pointer 'rec' to an
'unsigned char *' pointer, prior to passing the dereferenced pointer to
the isspace() macro.

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

Hi René,

If you need to re-roll your 'rs/xdiff-hunk-with-func-line' branch, could
you please squash this (or something like it) into the relevant patch.

[A comment in the linux <ctype.h> header, says that the ctype-info tables ...
   point into arrays of 384, so they can be indexed by any `unsigned
   char' value [0,255]; by EOF (-1); or by any `signed char' value
   [-128,-1).
So, this is not a problem on linux.]

Thanks!

ATB,
Ramsay Jones

 xdiff/xemit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index d0c0738..ae9adac 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -160,7 +160,7 @@ static int is_empty_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
 	const char *rec;
 	long len = xdl_get_rec(xdf, ri, &rec);
 
-	while (len > 0 && isspace(*rec)) {
+	while (len > 0 && isspace(*((unsigned char *)rec))) {
 		rec++;
 		len--;
 	}
-- 
2.8.0

             reply	other threads:[~2016-05-25 23:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-25 23:06 Ramsay Jones [this message]
2016-05-26  2:22 ` [PATCH] xemit.c: fix a [-Wchar-subscripts] compiler warning René Scharfe

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=57462FF3.4010705@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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 NNTP newsgroup(s).