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

Re: Compiler warning after workers/39825



On Mon, Nov 7, 2016, at 03:50 PM, Bart Schaefer wrote:
> ../../zsh-5.0/Src/utils.c: In function `mb_metastrlenend':
> ../../zsh-5.0/Src/utils.c:5344: warning: comparison is always true due to
> limited range of data type
> 
> commit 9c68ef08

Attached is patch that should work for both signed and unsigned
integers. Does it emit any warning?

On current system warmup the test results are 2141 ms vs 2337 ms,
slightly less than 10%, but still ~200 ms difference.

-- 
  Sebastian Gniazdowski
  psprint@xxxxxxxxxxxx
diff --git a/Src/utils.c b/Src/utils.c
index 733f570..32e7dc6 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5341,7 +5341,12 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	    inchar = *ptr;
 	ptr++;
 
-	if (complete && (inchar >= 0 && inchar <= 0x7f)) {
+        /*
+         * 0x7f is all ones except for top bit in binary,
+         * this will check if inchar is in range 0 .. 127
+         * inclusive, regardless of char signedness
+         */
+	if (complete && (inchar & 0x7f) == inchar) {
 	    /*
 	     * 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