From e79ad21aebfe1dc4227ae1f8dd3a2f1c0b5ba193 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Tue, 3 Jul 2012 23:11:06 +0200 Subject: [PATCH] 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. --- src/keycode.cpp | 16 ++++++++++------ 1 file 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"); } } -- 2.25.1