diff options
author | Bruno Haible <bruno@clisp.org> | 2023-05-04 23:22:14 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-05-05 13:04:11 +0200 |
commit | 78b1f3957a068a18428d8109042521ea48de6c05 (patch) | |
tree | 52f2328248de3e332de6d3fa3a0151c7d575fa3a | |
parent | 02a95ede0c9a6634ce0a72d5f8508104b8fb8951 (diff) | |
download | gnulib-stable-202207.tar.gz |
wcswidth: Fix result in case of overflow.stable-202207
* 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 | 21 |
2 files changed, 23 insertions, 4 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 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; } |