From 899569f653c33e8e934a4bfc194f205d5f80de6c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 15 Sep 2026 13:31:21 +0300 Subject: [PATCH] Fix PDC_wcstombs() for an output that exactly fills the buffer wcstombs() returns n when the converted string fills all n bytes; that is not an error. Also compare the result with (size_t)-1 instead of casting it to int. Fixes #390. --- pdcurses/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdcurses/util.c b/pdcurses/util.c index bd00fb50..8c3105e5 100644 --- a/pdcurses/util.c +++ b/pdcurses/util.c @@ -499,8 +499,8 @@ size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n) # else size_t i = wcstombs(dest, src, n); # endif - assert( -1 != (int)i && i < n); - if( (int)i < 0 || i >= n) /* invalid sequence or insufficient space */ + assert( i == (size_t)-1 || i <= n); + if( i == (size_t)-1) /* invalid sequence */ *dest = '\0'; else dest[i] = '\0';