Skip to content

Commit aefe807

Browse files
committedMar 2, 2015
Fix narrow_to_wide_c (ANDROID)
* Ensure converted string is NUL terminated * Restore logic to that used prior to 9e2a9b5
1 parent 773aa8c commit aefe807

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎src/util/string.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,18 @@ const wchar_t *narrow_to_wide_c(const char *mbs)
8383
size_t mbl = strlen(mbs);
8484
wchar_t *wcs = new wchar_t[mbl + 1];
8585

86-
for (size_t i = 0; i < mbl; i++) {
86+
size_t i, dest_i = 0;
87+
for (i = 0; i < mbl; i++) {
8788
if (((unsigned char) mbs[i] > 31) &&
8889
((unsigned char) mbs[i] < 127)) {
89-
wcs[i] = wide_chars[(unsigned char) mbs[i] - 32];
90+
wcs[dest_i++] = wide_chars[(unsigned char) mbs[i] - 32];
9091
}
9192
//handle newline
9293
else if (mbs[i] == '\n') {
93-
wcs[i] = L'\n';
94+
wcs[dest_i++] = L'\n';
9495
}
9596
}
97+
wcs[dest_i] = '\0';
9698

9799
return wcs;
98100
}

0 commit comments

Comments
 (0)
Please sign in to comment.