Skip to content

Commit 55b0d7b

Browse files
committed
Added CCHARW_MAX (limit on total characters in a cell)
The total characters in a cell (base character plus combining characters), plus a '\0' terminator, will be less than CCHARW_MAX (currently set to 20, which should be much more than sufficient for most purposes). This value is available on ncurses (and apparently not elsewhere), but any ncurses implementation really ought to have such a limit. Further work will be needed here. You can, for example, (still) use waddch( ) to add an arbitrary number of combining characters; this needs to be revised so that waddch( ) returns ERR when needed. Also, if any of the characters are in the Supplemental Multilingual Plane (SMP), they will actually be translated into _two_ wchar_t values using Unicode surrogates on Microsoft Windows (and, theoretically, any other platform similarly bedeviled by 16-bit wchar_t values). Fix follows from some points made by Robin Haberkorn on the bug-ncurses mailing list.
1 parent ac0c945 commit 55b0d7b

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

curses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Defined by this header:
4545
#define PDC_VER_CHANGE 4
4646
#define PDC_VER_YEAR 2026
4747
#define PDC_VER_MONTH 01
48-
#define PDC_VER_DAY 07
48+
#define PDC_VER_DAY 31
4949

5050
#define PDC_STRINGIZE( x) #x
5151
#define PDC_stringize( x) PDC_STRINGIZE( x)
@@ -148,6 +148,7 @@ typedef unsigned char bool;
148148
#define PDC_LONG_MMASK
149149
#ifdef PDC_WIDE
150150
#define USING_COMBINING_CHARACTER_SCHEME
151+
#define CCHARW_MAX 20
151152
#endif
152153
#endif
153154

pdcurses/util.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static int _int32_to_wchar_array( wchar_t *obuff, const int obuffsize, const int
274274
int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
275275
short *color_pair, void *opts)
276276
{
277-
int32_t c[20];
277+
int32_t c[CCHARW_MAX];
278278
int n = 0;
279279

280280
assert( wcval);
@@ -285,7 +285,7 @@ int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
285285
fullwidth character to its left. If c[0] > 0x110001, it's
286286
a marker for a combining character string. */
287287
#ifdef USING_COMBINING_CHARACTER_SCHEME
288-
while( n < 10 && c[n] >= COMBINED_CHAR_START)
288+
while( n < CCHARW_MAX - 1 && c[n] >= COMBINED_CHAR_START)
289289
{
290290
cchar_t added;
291291

@@ -308,7 +308,7 @@ int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
308308
c[i] = c[j];
309309
c[j] = swap_val;
310310
}
311-
_int32_to_wchar_array( wch, 20, c);
311+
_int32_to_wchar_array( wch, CCHARW_MAX, c);
312312
assert( attrs);
313313
assert( color_pair);
314314
if (!attrs || !color_pair)
@@ -325,17 +325,18 @@ int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
325325
int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs,
326326
short color_pair, const void *opts)
327327
{
328-
int32_t ochar[20], rval;
328+
int32_t ochar[CCHARW_MAX], rval;
329+
const int integer_color_pair = (opts ? *(int *)opts : (int)color_pair);
329330
#ifdef USING_COMBINING_CHARACTER_SCHEME
330331
int i;
331332
#endif
332333

333-
const int integer_color_pair = (opts ? *(int *)opts : (int)color_pair);
334334
assert( wcval);
335335
assert( wch);
336336
if (!wcval || !wch)
337337
return ERR;
338-
_wchar_to_int32_array( ochar, 20, wch);
338+
if( _wchar_to_int32_array( ochar, CCHARW_MAX, wch) < 0)
339+
return ERR;
339340
rval = ochar[0];
340341
/* If len_out > 1, we have combining characters. See */
341342
/* 'addch.c' for a discussion of how we handle those. */

0 commit comments

Comments
 (0)