{"thread":{"id":"42452","subject":"[PATCH] xemit.c: fix a [-Wchar-subscripts] compiler warning","startedAt":"2016-05-25T23:06:27Z","lastAt":"2016-05-26T02:22:04Z","messageCount":2,"participants":["Ramsay Jones","René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"287537","messageId":"57462FF3.4010705@ramsayjones.plus.com","threadId":"42452","inReplyTo":null,"subject":"[PATCH] xemit.c: fix a [-Wchar-subscripts] compiler warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2016-05-25T23:06:27Z","receivedAt":"2016-05-25T23:06:27Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nWhile compiling on cygwin (x86_64), gcc complains thus:\n\n      CC xdiff/xemit.o\n  xdiff/xemit.c: In function ‘is_empty_rec’:\n  xdiff/xemit.c:163:2: warning: array subscript has type ‘char’ [-Wchar-subscripts]\n    while (len > 0 && isspace(*rec)) {\n    ^\n\nA comment in the <ctype.h> header reads, in part, like so:\n\n   These macros are intentionally written in a manner that will trigger\n   a gcc -Wall warning if the user mistakenly passes a 'char' instead\n   of an int containing an 'unsigned char'.\n\nIn order to suppress the warning, cast the 'char *' pointer 'rec' to an\n'unsigned char *' pointer, prior to passing the dereferenced pointer to\nthe isspace() macro.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n\nHi René,\n\nIf you need to re-roll your 'rs/xdiff-hunk-with-func-line' branch, could\nyou please squash this (or something like it) into the relevant patch.\n\n[A comment in the linux <ctype.h> header, says that the ctype-info tables ...\n   point into arrays of 384, so they can be indexed by any `unsigned\n   char' value [0,255]; by EOF (-1); or by any `signed char' value\n   [-128,-1).\nSo, this is not a problem on linux.]\n\nThanks!\n\nATB,\nRamsay Jones\n\n xdiff/xemit.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/xdiff/xemit.c b/xdiff/xemit.c\nindex d0c0738..ae9adac 100644\n--- a/xdiff/xemit.c\n+++ b/xdiff/xemit.c\n@@ -160,7 +160,7 @@ static int is_empty_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)\n \tconst char *rec;\n \tlong len = xdl_get_rec(xdf, ri, &rec);\n \n-\twhile (len > 0 && isspace(*rec)) {\n+\twhile (len > 0 && isspace(*((unsigned char *)rec))) {\n \t\trec++;\n \t\tlen--;\n \t}\n-- \n2.8.0\n"},{"id":"287548","messageId":"57465DCC.9080809@web.de","threadId":"42452","inReplyTo":"57462FF3.4010705@ramsayjones.plus.com","subject":"Re: [PATCH] xemit.c: fix a [-Wchar-subscripts] compiler warning","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-05-26T02:22:04Z","receivedAt":"2016-05-26T02:22:04Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"[sorry for duplicate]\n\nAm 26.05.2016 um 01:06 schrieb Ramsay Jones:\n>\n> While compiling on cygwin (x86_64), gcc complains thus:\n>\n>        CC xdiff/xemit.o\n>    xdiff/xemit.c: In function ‘is_empty_rec’:\n>    xdiff/xemit.c:163:2: warning: array subscript has type ‘char’ [-Wchar-subscripts]\n>      while (len > 0 && isspace(*rec)) {\n>      ^\n\nAh, it's not using our own isspace(), which works fine with signed \nchars, because it doesn't include git-compat-util.h.  I'm spoilt by \nthose char classifier macros that can be actually used with chars.. \nThanks for catching!\n\nRené\n"}]}