Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Compiler warning after workers/39825



On Mon, 07 Nov 2016 23:24:23 -0800
Sebastian Gniazdowski <psprint@xxxxxxxxxxxx> wrote:
> Ah, the (mild) enlightenment is: char can be signed / unsigned. Wonder
> if this can have any actual implications as 7f is AFAIK still in
> unsigned range. For sure there are some techniques of solving such
> portability problems hm

Yes, that's it.  We have a macro to perform a safe cast to unsigned.
That's the right answer, since if the char is signed and is negative,
it's *not* in a range we want to deal with.  So the compiler was right...

Casting 0x74 is unnecessary, since the constant will conform with
unsigned char anyway, but I've made the point...

pws

diff --git a/Src/utils.c b/Src/utils.c
index 733f570..d73110a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5341,7 +5341,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	    inchar = *ptr;
 	ptr++;
 
-	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
+	if (complete && (inchar >= 0 && STOUC(inchar) <= STOUC(0x7f))) {
 	    /*
 	     * We rely on 7-bit US-ASCII as a subset, so skip
 	     * multibyte handling if we have such a character.



Messages sorted by: Reverse Date, Date, Thread, Author