diff options
author | Craig Robbins <kde.psych@gmail.com> | 2015-03-02 13:16:01 +1000 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-15 10:17:09 +0100 |
commit | a740a48f62261073190a92e9b60256da13817923 (patch) | |
tree | ae3359ecf4d095b64bf71c4578223eff4858093a | |
parent | b12f569fc6b78c1e657bc0cfd8518b997d5f83c7 (diff) | |
download | minetest-a740a48f62261073190a92e9b60256da13817923.tar.gz minetest-a740a48f62261073190a92e9b60256da13817923.tar.bz2 minetest-a740a48f62261073190a92e9b60256da13817923.zip |
Fix narrow_to_wide_c (ANDROID)
* Ensure converted string is NUL terminated
* Restore logic to that used prior to 9e2a9b5
-rw-r--r-- | src/util/string.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp index de669b473..a29bce94b 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -78,16 +78,18 @@ const wchar_t *narrow_to_wide_c(const char *mbs) size_t mbl = strlen(mbs); wchar_t *wcs = new wchar_t[mbl + 1]; - for (size_t i = 0; i < mbl; i++) { + size_t i, dest_i = 0; + for (i = 0; i < mbl; i++) { if (((unsigned char) mbs[i] > 31) && ((unsigned char) mbs[i] < 127)) { - wcs[i] = wide_chars[(unsigned char) mbs[i] - 32]; + wcs[dest_i++] = wide_chars[(unsigned char) mbs[i] - 32]; } //handle newline else if (mbs[i] == '\n') { - wcs[i] = L'\n'; + wcs[dest_i++] = L'\n'; } } + wcs[dest_i] = '\0'; return wcs; } |