From 9b25b0b91f6b4b311de57b50f81339fe3825c339 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 15 Sep 2026 13:13:12 +0300 Subject: [PATCH] Fix setcchar() for an empty wide string The combining-character loop read past the terminating zero into the uninitialised rest of the array. Fixes #388. --- pdcurses/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pdcurses/util.c b/pdcurses/util.c index bd00fb50..389584cb 100644 --- a/pdcurses/util.c +++ b/pdcurses/util.c @@ -329,6 +329,7 @@ int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, { int32_t ochar[CCHARW_MAX], rval; const int integer_color_pair = (opts ? *(int *)opts : (int)color_pair); + int n; #ifdef USING_COMBINING_CHARACTER_SCHEME int i; #endif @@ -337,13 +338,14 @@ int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, assert( wch); if (!wcval || !wch) return ERR; - if( _wchar_to_int32_array( ochar, CCHARW_MAX, wch) < 0) + n = _wchar_to_int32_array( ochar, CCHARW_MAX, wch); + if( n < 0) return ERR; rval = ochar[0]; - /* If len_out > 1, we have combining characters. See */ + /* If n > 1, we have combining characters. See */ /* 'addch.c' for a discussion of how we handle those. */ #ifdef USING_COMBINING_CHARACTER_SCHEME - for( i = 1; ochar[i]; i++) + for( i = 1; i < n; i++) rval = COMBINED_CHAR_START + PDC_find_combined_char_idx( rval, ochar[i]); #endif *wcval = rval | attrs | COLOR_PAIR(integer_color_pair);