diff options
author | Andreas Zwinkau <qznc@go.to> | 2012-07-03 23:11:06 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-07-21 22:08:20 +0300 |
commit | e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193 (patch) | |
tree | 47febc545e464de15f0603d4a0bb2281cdea3e8c | |
parent | 0b612539318a688ad24b66392bf39aedf8a01f62 (diff) | |
download | minetest-e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193.tar.gz minetest-e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193.tar.bz2 minetest-e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193.zip |
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.
-rw-r--r-- | src/keycode.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/keycode.cpp b/src/keycode.cpp index 30d1dd5a2..c3c06bb7f 100644 --- a/src/keycode.cpp +++ b/src/keycode.cpp @@ -258,9 +258,10 @@ KeyPress::KeyPress(const char *name) try { Key = keyname_to_keycode(name); m_name = name; - if (strlen(name) > 8) - mbtowc(&Char, name + 8, 1); - else + if (strlen(name) > 8) { + int chars_read = mbtowc(&Char, name + 8, 1); + assert (chars_read == 1 && "unexpected multibyte character"); + } else Char = L'\0'; return; } catch (UnknownKeycode &e) {}; @@ -270,7 +271,8 @@ KeyPress::KeyPress(const char *name) m_name += name; try { 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; } catch (UnknownKeycode &e) {}; } @@ -279,7 +281,8 @@ KeyPress::KeyPress(const char *name) 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]; } @@ -292,7 +295,8 @@ KeyPress::KeyPress(const irr::SEvent::SKeyInput &in) } else { size_t maxlen = wctomb(NULL, Char); m_name.resize(maxlen+1, '\0'); - wctomb(&m_name[0], Char); + int written = wctomb(&m_name[0], Char); + assert (written >= 0 && "unexpected multibyte character"); } } |