xemit.c: fix a [-Wchar-subscripts] compiler warning
PATCH 1/1 xemit.c: fix a [-Wchar-subscripts] compiler warning
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.
---
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(-)
xdiff/xemit.c +1 -1
@@ -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--; }
Signature · 1 line
2.8.0
[sorry for duplicate]
Am 26.05.2016 um 01:06 schrieb Ramsay Jones:
Quoted 8 lines
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)) { ^
Ah, it's not using our own isspace(), which works fine with signed chars, because it doesn't include git-compat-util.h. I'm spoilt by those char classifier macros that can be actually used with chars.. Thanks for catching!
René