Skip to content

Commit

Permalink
Fix for non-UTF-8 wide charsets (Solaris patch 050-CR7065478)
Browse files Browse the repository at this point in the history
This upstreams a Solaris patch:
https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/050-CR7065478.patch

src/lib/libast/comp/setlocale.c:
- Add wide_wctomb() wrapper for wctomb(3). It changes an invalid
  character (wctomb returns -1) to a single byte with length 1.
- set_ctype(): Use wide_wctomb() instead of wctomb(3) as the
  conversion discipline function (ast.mb_conv). Effectively this
  means there are no invalid characters. Perhaps this is necessary
  for compatibility with ASCII. Sadly, no public info available.
  • Loading branch information
McDutchie committed Jan 9, 2021
1 parent 096f46e commit e03c010
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lib/libast/comp/setlocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,23 @@ iswalpha(wchar_t c)

typedef int (*Isw_f)(wchar_t);

static int
wide_wctomb(char* u, wchar_t w)
{
int size = 0;

if (u)
{
size = wctomb(u, w);
if (size < 0)
{
*u = (char)(w & 0xff);
size = 1;
}
}
return size;
}

/*
* called when LC_CTYPE initialized or changes
*/
Expand Down Expand Up @@ -2261,7 +2278,7 @@ set_ctype(Lc_category_t* cp)
{
if (!(ast.mb_width = wcwidth))
ast.mb_width = default_wcwidth;
ast.mb_conv = wctomb;
ast.mb_conv = wide_wctomb;
#ifdef mb_state
{
/*
Expand Down

0 comments on commit e03c010

Please sign in to comment.