From: Andreas Zwinkau Date: Tue, 3 Jul 2012 21:11:06 +0000 (+0200) Subject: Remove mbtowc warnings X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193;p=zefram%2Fminetest%2Fminetest_engine.git 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. --- diff --git a/src/keycode.cpp b/src/keycode.cpp index 30d1dd5a..c3c06bb7 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"); } }