From: Karel Zak Date: Wed, 18 Mar 2026 11:48:54 +0000 (+0100) Subject: mbsalign: cleanup escape sequences handling X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32f305b22f0cd88c91096294566b9d55cc4b0f41;p=thirdparty%2Futil-linux.git mbsalign: cleanup escape sequences handling Use '\033' (portable) instead of '\e' (GNU extension), simplify the control character handling by checking for ESC directly, and fix the SCS boundary check to only match complete sequences. Signed-off-by: Karel Zak --- diff --git a/lib/mbsalign.c b/lib/mbsalign.c index 3e79ad10b..3a1385fec 100644 --- a/lib/mbsalign.c +++ b/lib/mbsalign.c @@ -42,14 +42,9 @@ size_t mbs_nwidth(const char *buf, size_t bufsz) last = p + (bufsz - 1); while (p && *p && p <= last) { - if (iscntrl((unsigned char) *p)) { - char ctrl_char = *p; + if (*p == '\033') { p++; - /* only process escape sequences if the control char is ESC */ - if (ctrl_char != '\e') - continue; - /* try detect "\e[x;ym" and skip on success */ if (*p && *p == '[') { const char *e = p; @@ -59,11 +54,12 @@ size_t mbs_nwidth(const char *buf, size_t bufsz) p = e + 1; } /* try detect SCS sequences "\e(X", "\e)X", "\e*X", "\e+X" and skip on success */ - else if (*p && (*p == '(' || *p == ')' || *p == '*' || *p == '+')) { - p++; /* skip the SCS introducer */ - if (p <= last) - p++; /* skip the character */ - } + else if (p < last && (*p == '(' || *p == ')' || *p == '*' || *p == '+')) + p += 2; /* skip the SCS sequence */ + continue; + } + if (iscntrl((unsigned char) *p)) { + p++; continue; } #ifdef HAVE_WIDECHAR