diff options
author | Bruno Haible <bruno@clisp.org> | 2023-05-04 23:22:14 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-05-05 12:40:58 +0200 |
commit | 74e52265c7d4df498b054befaeb0823b9e07cfc2 (patch) | |
tree | f749fa2f1d76da0f2995c281572ea24a7e662da2 | |
parent | ad1a62569845a5f9ea9e8eaae38b6d2677d7fded (diff) | |
download | gnulib-stable-202301.tar.gz |
wcswidth: Fix result in case of overflow.stable-202301
* lib/wcswidth-impl.h (wcswidth): Continue searching for a non-printing
wide character after the total width has become > INT_MAX.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/wcswidth-impl.h | 19 |
2 files changed, 22 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2023-05-04 Bruno Haible <bruno@clisp.org> + + wcswidth: Fix result in case of overflow. + * lib/wcswidth-impl.h (wcswidth): Continue searching for a non-printing + wide character after the total width has become > INT_MAX. + 2023-05-03 Bruno Haible <bruno@clisp.org> vasnprintf: Make '0' flag handling more ISO C compliant. diff --git a/lib/wcswidth-impl.h b/lib/wcswidth-impl.h index 606b3bdc1a..ce0b2e0877 100644 --- a/lib/wcswidth-impl.h +++ b/lib/wcswidth-impl.h @@ -35,9 +35,22 @@ wcswidth (const wchar_t *s, size_t n) } return count; + /* The total width has become > INT_MAX. + Continue searching for a non-printing wide character. */ + for (; n > 0; s++, n--) + { + wchar_t c = *s; + if (c == (wchar_t)'\0') + break; + { + int width = wcwidth (c); + if (width < 0) + goto found_nonprinting; + } + overflow: ; + } + return INT_MAX; + found_nonprinting: return -1; - - overflow: - return INT_MAX; } |