diff options
Diffstat (limited to 'lib/wcswidth-impl.h')
-rw-r--r-- | lib/wcswidth-impl.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/wcswidth-impl.h b/lib/wcswidth-impl.h index e9da91a19e..ce0b2e0877 100644 --- a/lib/wcswidth-impl.h +++ b/lib/wcswidth-impl.h @@ -1,5 +1,5 @@ /* Determine number of screen columns needed for a size-bounded wide string. - Copyright (C) 1999, 2011-2022 Free Software Foundation, Inc. + Copyright (C) 1999, 2011-2023 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 1999. This file is free software: you can redistribute it and/or modify @@ -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; } |