Add extra NUL termination check for string length in win32 general string convertors

This commit is contained in:
gingerBill
2020-06-12 15:01:43 +01:00
parent be76c860a5
commit 58466a6f3b

View File

@@ -791,8 +791,10 @@ utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
}
text[n] = 0;
return text[:len(text)-1];
for n >= 0 && text[n] == 0 {
n -= 1;
}
return text[:n];
}
utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> Wstring {
if res := utf8_to_utf16(s, allocator); res != nil {
@@ -821,7 +823,10 @@ utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
text[n] = 0;
return string(text[:len(text)-1]);
for n >= 0 && text[n] == 0 {
n -= 1;
}
return string(text[:n]);
}