On 03/10/2026 22:41, Bruno Haible wrote:
Pádraig Brady wrote:
This seems to have missed some overflow cases
(which I noticed when auditing c32width() usage in coreutils/gnulib).
Indeed, yes, I missed these in 2011.
I'll push the attached later to address this.
But the function also has another problem: When the count overflows
before an unprintable character is encountered in the string, the
function currently returns INT_MAX, where it should in fact return -1.
The following patches fix that, making your proposed patch unnecessary.
2026-10-03 Bruno Haible <[email protected]>
mbswidth: Fix overflow handling.
* lib/mbswidth.c: Include <stdint.h>.
(mbsnwidth): When the width accumulator becomes > INT_MAX before an
unprintable character is seen, return -1, not INT_MAX.
* modules/mbswidth (Depends-on): Add stdint-h, assert-h.
2026-10-03 Bruno Haible <[email protected]>
wcswidth, c32swidth: Simplify.
* lib/wcswidth.c: Include <stdint.h>.
* lib/c32swidth.c: Likewise.
* lib/wcswidth-impl.h (FUNC): Simplify by using a large-enough 'count'
variable.
* modules/wcswidth (Depends-on): Add stdint-h, assert-h.
* modules/c32swidth (Depends-on): Likewise.
OK cool.
I see they assume no more than 2 columns per byte,
which is practically fine I think.
Theoretically one could construct a custom locale
that caused wcwidth() to return larger values
to break that assumption, but that's probably not
worth worrying about.
thanks!
Padraig