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

num_in_chars incremented after each mbrtowc()



Hello,
while working my hands off on implementing display width handling in
params.c rather than subst.c I encountered a bug in mb_metastrlenend.
It will reveal itself only on improper unicode strings.

Best regards,
Sebastian Gniazdowski
diff --git a/Src/utils.c b/Src/utils.c
index ca810de..b0a6625 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5072,10 +5072,9 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	    inchar = *ptr;
 	ptr++;
 	ret = mbrtowc(&wc, &inchar, 1, &mb_shiftstate);
+        num_in_char++;
 
-	if (ret == MB_INCOMPLETE) {
-	    num_in_char++;
-	} else {
+	if (ret != MB_INCOMPLETE) {
 	    if (ret == MB_INVALID) {
 		/* Reset, treat as single character */
 		memset(&mb_shiftstate, 0, sizeof(mb_shiftstate));


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