MB_CUR_MAX from stdlib.h isn't a compile-time constant so can't be used
for the size of a couple of static char arrays so malloc() was used at
run time, with the tiny claims never being freed. valgrind(1) noticed
and David suggested MB_LEN_MAX from limits.h instead; that header's
contents are suitable for #if expressions and thus compile-time
constants.
cpstripped (charstring_t dest, size_t max, char *str)
{
static bool deja_vu;
cpstripped (charstring_t dest, size_t max, char *str)
{
static bool deja_vu;
+ static char oddchar[MB_LEN_MAX * 2];
- static char *spacechar;
+ static char spacechar[MB_LEN_MAX * 2];
static size_t spacelen;
char *end;
bool squash;
static size_t spacelen;
char *end;
bool squash;
- two = MB_CUR_MAX * 2; /* Varies at run-time. */
-
- oddchar = mh_xmalloc(two);
- oddlen = wcstombs(oddchar, L"?", two);
+ oddlen = wcstombs(oddchar, L"?", sizeof oddchar);
assert(wcwidth(L' ') == 1); /* Need to pad in ones. */
assert(wcwidth(L' ') == 1); /* Need to pad in ones. */
- spacechar = mh_xmalloc(two);
- spacelen = wcstombs(spacechar, L" ", two);
+ spacelen = wcstombs(spacechar, L" ", sizeof spacechar);