From 72585aa30d2fa834985fb90a79497860dd67e506 Mon Sep 17 00:00:00 2001 From: Gregor Schneider Date: Sat, 11 Apr 2009 21:24:25 +0000 Subject: [PATCH] - Don't copy data to null buffer, just return the string length in this case - Fix some buffer calculation problems, handle buffer termination if it's shorter than the font string - Fixes >= 10 gdi32 font winetests (NtGdiGetTextFaceW/NtGdiGetTextFaceA related) svn path=/trunk/; revision=40469 --- .../subsystems/win32/win32k/objects/text.c | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/reactos/subsystems/win32/win32k/objects/text.c b/reactos/subsystems/win32/win32k/objects/text.c index d252eada041..f2bef67baca 100644 --- a/reactos/subsystems/win32/win32k/objects/text.c +++ b/reactos/subsystems/win32/win32k/objects/text.c @@ -326,6 +326,7 @@ NtGdiGetTextFaceW( HFONT hFont; PTEXTOBJ TextObj; NTSTATUS Status; + INT fLen, ret; /* FIXME: Handle bAliasName */ @@ -341,16 +342,32 @@ NtGdiGetTextFaceW( TextObj = RealizeFontInit(hFont); ASSERT(TextObj != NULL); - Count = min(Count, wcslen(TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfFaceName)); - Status = MmCopyToCaller(FaceName, TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfFaceName, Count * sizeof(WCHAR)); - TEXTOBJ_UnlockText(TextObj); - if (!NT_SUCCESS(Status)) + fLen = wcslen(TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfFaceName) + 1; + + if (FaceName != NULL) { - SetLastNtError(Status); - return 0; + Count = min(Count, fLen); + Status = MmCopyToCaller(FaceName, TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfFaceName, Count * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + { + TEXTOBJ_UnlockText(TextObj); + SetLastNtError(Status); + return 0; + } + /* Terminate if we copied only part of the font name */ + if (Count > 0 && Count < fLen) + { + FaceName[Count - 1] = '\0'; + } + ret = Count; + } + else + { + ret = fLen; } - return Count; + TEXTOBJ_UnlockText(TextObj); + return ret; } W32KAPI