1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-23 08:08:47 -05:00

Fix wctomb use

wctomb(NULL, _) returns "nonzero if the encoding has nontrivial shift state, or zero if the encoding is stateless."

I assume the intentation was to get the size of the target buffer.
Use MB_CUR_MAX for this.
This commit is contained in:
Andreas Zwinkau 2012-07-03 23:13:15 +02:00 committed by Perttu Ahola
parent e79ad21aeb
commit 28e7443f9b

View File

@ -293,8 +293,7 @@ KeyPress::KeyPress(const irr::SEvent::SKeyInput &in)
if (valid_kcode(Key)) { if (valid_kcode(Key)) {
m_name = KeyNames[Key]; m_name = KeyNames[Key];
} else { } else {
size_t maxlen = wctomb(NULL, Char); m_name.resize(MB_CUR_MAX+1, '\0');
m_name.resize(maxlen+1, '\0');
int written = wctomb(&m_name[0], Char); int written = wctomb(&m_name[0], Char);
assert (written >= 0 && "unexpected multibyte character"); assert (written >= 0 && "unexpected multibyte character");
} }