From aefe80769bc515e0ddbfc734d41de396aca1259c Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Mon, 2 Mar 2015 13:16:01 +1000 Subject: [PATCH] Fix narrow_to_wide_c (ANDROID) * Ensure converted string is NUL terminated * Restore logic to that used prior to 9e2a9b5 --- src/util/string.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/string.cpp b/src/util/string.cpp index 9e2123d59..c48abe835 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -83,16 +83,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; }