Index: reactos/win32ss/gdi/gdi32/objects/text.c =================================================================== --- reactos/win32ss/gdi/gdi32/objects/text.c (revision 75509) +++ reactos/win32ss/gdi/gdi32/objects/text.c (working copy) @@ -3,6 +3,35 @@ #define NDEBUG #include +static +VOID +UnicodeStringFromBufWithLen( + _Out_ PUNICODE_STRING StringU, + _In_ LPCSTR lpString, + _In_ INT cchString) +{ + ANSI_STRING StringA; + + if (lpString != NULL) + { + if (cchString == -1) + { + RtlInitAnsiString(&StringA, lpString); + } + else + { + StringA.Buffer = lpString; + StringA.Length = StringA.MaximumLength = cchString; + } + RtlAnsiStringToUnicodeString(StringU, &StringA, TRUE); + } + else + { + StringU->Buffer = NULL; + StringU->Length = StringU->MaximumLength = 0; + } +} + /* * @implemented */ @@ -15,23 +44,15 @@ _In_reads_(cchString) LPCSTR lpString, _In_ INT cchString) { - ANSI_STRING StringA; UNICODE_STRING StringU; BOOL bResult; - if (lpString != NULL) - { - RtlInitAnsiString(&StringA, (LPSTR)lpString); - RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE); - } - else - { - StringU.Buffer = NULL; - } + UnicodeStringFromBufWithLen(&StringU, lpString, cchString); bResult = TextOutW(hdc, nXStart, nYStart, StringU.Buffer, cchString); RtlFreeUnicodeString(&StringU); + return bResult; } @@ -223,12 +244,10 @@ _In_ INT cchString, _Out_ LPSIZE lpsz) { - ANSI_STRING StringA; UNICODE_STRING StringU; BOOL ret; - RtlInitAnsiString(&StringA, (LPSTR)lpString); - RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE); + UnicodeStringFromBufWithLen(&StringU, lpString, cchString); ret = GetTextExtentPointW(hdc, StringU.Buffer, cchString, lpsz); @@ -310,8 +329,7 @@ _Out_writes_to_opt_ (cchString, *lpnFit) LPINT lpnDx, _Out_ LPSIZE lpSize) { - NTSTATUS Status; - LPWSTR lpszStrW; + UNICODE_STRING StringU; BOOL bResult = FALSE; if (nMaxExtent < -1) @@ -320,15 +338,10 @@ return FALSE; } - Status = HEAP_strdupA2W(&lpszStrW, lpszStr); - if (!NT_SUCCESS (Status)) - { - SetLastError(RtlNtStatusToDosError(Status)); - return FALSE; - } + UnicodeStringFromBufWithLen(&StringU, lpszStr, cchString); bResult = NtGdiGetTextExtentExW(hdc, - lpszStrW, + StringU.Buffer, cchString, nMaxExtent, (PULONG)lpnFit, @@ -336,7 +349,7 @@ lpSize, 0); - HEAP_free(lpszStrW); + RtlFreeUnicodeString(&StringU); return bResult; } @@ -353,13 +366,10 @@ _In_ INT cchString, _Out_ LPSIZE lpSize) { - ANSI_STRING StringA; UNICODE_STRING StringU; BOOL ret; - StringA.Buffer = (LPSTR)lpString; - StringA.Length = cchString; - RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE); + UnicodeStringFromBufWithLen(&StringU, lpString, cchString); ret = GetTextExtentPoint32W(hdc, StringU.Buffer, cchString, lpSize); @@ -433,17 +443,15 @@ _In_ UINT fuOptions, _In_opt_ const RECT *lprc, _In_reads_opt_(cch) LPCSTR lpString, - _In_ UINT cch, + _In_ UINT cchString, _In_reads_opt_(cch) const INT *lpDx) { - ANSI_STRING StringA; UNICODE_STRING StringU; BOOL ret; - RtlInitAnsiString(&StringA, (LPSTR)lpString); - RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE); + UnicodeStringFromBufWithLen(&StringU, lpString, cchString); - ret = ExtTextOutW(hdc, x, y, fuOptions, lprc, StringU.Buffer, cch, lpDx); + ret = ExtTextOutW(hdc, x, y, fuOptions, lprc, StringU.Buffer, cchString, lpDx); RtlFreeUnicodeString(&StringU);