diff options
author | Bruno Haible <bruno@clisp.org> | 2023-05-04 23:22:14 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-05-04 23:22:14 +0200 |
commit | 59f878fa3d175b2d085a01a8df786c9e40be14b9 (patch) | |
tree | 0a90a2b4d6672e8c7e489a6c5a60e4961b1a1fd3 /lib | |
parent | 6424473acb6cdd106bdf6e1aaf16c746724eaa17 (diff) | |
download | gnulib-59f878fa3d175b2d085a01a8df786c9e40be14b9.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/wcswidth-impl.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/wcswidth-impl.h b/lib/wcswidth-impl.h index 644a093a7e..a879bfdd93 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; } |