From c69bf543cfe509d862fb4839133125773735ce94 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 8 Jan 2021 05:20:28 +0000 Subject: [PATCH] libcmd/wclib: Fix for wide char handling (Solaris 055-CR7026179) This change is pulled from here: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/055-CR7026179.patch It's a fix for wide-character handling in the wc (word count) library. --- src/lib/libcmd/wclib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index 0d52fda40707..61efd176b07b 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -341,6 +341,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) int xspace; int wasspace = 1; unsigned char* start; + int flagm = 0; lastchar = 0; start = (endbuff = side) + 1; @@ -367,6 +368,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) if(mbc(lasttype)) { c = lasttype; + flagm = 1; goto mbyte; } if(!lasttype && spc(type[*cp])) @@ -415,6 +417,14 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) skip = (c&7); adjust += skip; state = 0; + if(flagm==1) + { + flagm = 0; + oldc = *cp; + if(xspace && (iswspace(*cp)==1)) + state = 8; + continue; + } if(skip==2 && (cp[-1]&0xc)==0 && (state=(cp[-1]&0x3))) oldc = *cp; else if(xspace && cp[-1]==0xc2)