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-10 20:57:02 +01:00
committed by Peter Nelson
parent b37954722b
commit e2a796dbcd
8 changed files with 34 additions and 38 deletions
+1 -1
View File
@@ -147,7 +147,7 @@ static HFONT HFontFromFont(Font *font)
logfont.lfHeight = font->fc->GetHeight();
logfont.lfWeight = FW_NORMAL;
logfont.lfCharSet = DEFAULT_CHARSET;
convert_to_fs(font->fc->GetFontName(), logfont.lfFaceName, lengthof(logfont.lfFaceName));
convert_to_fs(font->fc->GetFontName(), logfont.lfFaceName);
return CreateFontIndirect(&logfont);
}