Remove mbtowc warnings

As mbtowc(_, _, 1) reads at most one char, everything other than a
return value of 1 is an error. Since the input strings are static,
an assert protects against future changes.

Likewise, wctomb should currently never encounter a character, which
actually needs a multibyte representation.
This commit is contained in:
Andreas Zwinkau 2012-07-03 23:11:06 +02:00 committed by Perttu Ahola
parent 0b61253931
commit e79ad21aeb
1 changed files with 10 additions and 6 deletions

View File

@ -258,9 +258,10 @@ KeyPress::KeyPress(const char *name)
try { try {
Key = keyname_to_keycode(name); Key = keyname_to_keycode(name);
m_name = name; m_name = name;
if (strlen(name) > 8) if (strlen(name) > 8) {
mbtowc(&Char, name + 8, 1); int chars_read = mbtowc(&Char, name + 8, 1);
else assert (chars_read == 1 && "unexpected multibyte character");
} else
Char = L'\0'; Char = L'\0';
return; return;
} catch (UnknownKeycode &e) {}; } catch (UnknownKeycode &e) {};
@ -270,7 +271,8 @@ KeyPress::KeyPress(const char *name)
m_name += name; m_name += name;
try { try {
Key = keyname_to_keycode(m_name.c_str()); Key = keyname_to_keycode(m_name.c_str());
mbtowc(&Char, name, 1); int chars_read = mbtowc(&Char, name, 1);
assert (chars_read == 1 && "unexpected multibyte character");
return; return;
} catch (UnknownKeycode &e) {}; } catch (UnknownKeycode &e) {};
} }
@ -279,7 +281,8 @@ KeyPress::KeyPress(const char *name)
Key = irr::KEY_KEY_CODES_COUNT; Key = irr::KEY_KEY_CODES_COUNT;
mbtowc(&Char, name, 1); int mbtowc_ret = mbtowc(&Char, name, 1);
assert (mbtowc_ret == 1 && "unexpected multibyte character");
m_name = name[0]; m_name = name[0];
} }
@ -292,7 +295,8 @@ KeyPress::KeyPress(const irr::SEvent::SKeyInput &in)
} else { } else {
size_t maxlen = wctomb(NULL, Char); size_t maxlen = wctomb(NULL, Char);
m_name.resize(maxlen+1, '\0'); m_name.resize(maxlen+1, '\0');
wctomb(&m_name[0], Char); int written = wctomb(&m_name[0], Char);
assert (written >= 0 && "unexpected multibyte character");
} }
} }