1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-28 14:44:28 +01:00

Codefix: Potential unterminated string returned from convert_to_fs.

Converting from UTF-8 to UTF-16 could have resulted in a buffer overflow if the buffer size was exactly the length of the converted string.

Pass string_view/span to convert_from/to_fs instead, and ensure the buffer is terminated. This replaces passing a pointer to the buffer and the buffer size as separate parameters, allowing the compiler to pass both in one parameter.

Removes use of `lengthof()`.
This commit is contained in:
Peter Nelson
2024-07-09 17:10:27 +01:00
committed by Peter Nelson
parent b37954722b
commit e2a796dbcd
8 changed files with 34 additions and 38 deletions

View File

@@ -360,7 +360,7 @@ static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
if (len > 0) {
static char utf8_buf[1024];
convert_from_fs(str.c_str(), utf8_buf, lengthof(utf8_buf));
convert_from_fs(str.c_str(), utf8_buf);
/* Convert caret position from bytes in the input string to a position in the UTF-8 encoded string. */
LONG caret_bytes = ImmGetCompositionString(hIMC, GCS_CURSORPOS, nullptr, 0);