Fixes: 1d3bfdc3abdaaa45075f0ec04228b911ab5ab8cf
-- v2: gdi32: Ensure null termination in logfont_AtoW.
From: Alex Henrie alexhenrie24@gmail.com
Fixes: 1d3bfdc3abdaaa45075f0ec04228b911ab5ab8cf --- dlls/gdi32/text.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/dlls/gdi32/text.c b/dlls/gdi32/text.c index 7725e832c6b..464379bd232 100644 --- a/dlls/gdi32/text.c +++ b/dlls/gdi32/text.c @@ -780,10 +780,11 @@ static void text_metric_ex_WtoA(const NEWTEXTMETRICEXW *tmW, NEWTEXTMETRICEXA *t
static void logfont_AtoW( const LOGFONTA *fontA, LPLOGFONTW fontW ) { + int len = MultiByteToWideChar( CP_ACP, 0, fontA->lfFaceName, + strnlen( fontA->lfFaceName, LF_FACESIZE ), + fontW->lfFaceName, LF_FACESIZE ); + fontW->lfFaceName[min(len, LF_FACESIZE - 1)] = 0; memcpy( fontW, fontA, sizeof(LOGFONTA) - LF_FACESIZE ); - MultiByteToWideChar( CP_ACP, 0, fontA->lfFaceName, strnlen( fontA->lfFaceName, LF_FACESIZE ), - fontW->lfFaceName, LF_FACESIZE ); - fontW->lfFaceName[LF_FACESIZE - 1] = 0; }
static void logfont_WtoA( const LOGFONTW *fontW, LPLOGFONTA fontA )
On Fri May 2 19:33:32 2025 +0000, Alex Henrie wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/7956/diffs?diff_id=175211&start_sha=2058dcf3735aff660968131654fc59814556cb57#ba343c47333e917866d8fb2e6afb80c733da0105_786_788)
In my opinion, instead of duplicating the source string `fontA->lfFaceName` and zeroing its last byte, it's a bit more elegant to use `min` to compute the correct location for the null terminator in the destination string `fontW->lfFaceName`.