Fix output with C locale

If given a prompt that includes a non-ascii char and a C locale, fish
currently fails to properly display it.

So you set `function fish_prompt; echo 😃; end` and it shows empty
space.

While the underlying cause is obviously using a C locale and non-C
characters to begin with, this is an unacceptable failure mode.

Apparently I misunderstood wcstombs, so I inadvertently broke this in
2b0b3d3 while trying to fix 5134949's crash.

Just return the offending bit to pre-5134949 levels, so instead of an
infinite recursion we just call a lame function a couple of times.
This commit is contained in:
Fabian Homborg 2020-03-11 20:29:12 +01:00
parent acad9b05e2
commit 1a063fe3c1

View File

@ -402,6 +402,11 @@ int outputter_t::writech(wint_t ch) {
void outputter_t::writestr(const wchar_t *str) { void outputter_t::writestr(const wchar_t *str) {
assert(str && "Empty input string"); assert(str && "Empty input string");
if (MB_CUR_MAX == 1) {
// Single-byte locale (C/POSIX/ISO-8859).
while (*str) writech(*str++);
return;
}
size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed
if (len == static_cast<size_t>(-1)) { if (len == static_cast<size_t>(-1)) {
debug(3, L"Tried to print invalid wide character string"); debug(3, L"Tried to print invalid wide character string");