From fcb8e0d77af374a2da1e33a76870f5ab412b9cb6 Mon Sep 17 00:00:00 2001 From: Bill Medland Date: Fri, 18 Jan 2002 18:09:09 +0000 Subject: [PATCH] - Don't string copy from uninitialised stack memory. In fact don't modify the input string if it didn't change. - Correct array size. - Logically separate the centring from the ellipsification. - Comment on prefix error. --- dlls/user/text.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dlls/user/text.c b/dlls/user/text.c index 3e1e3ef5665..2fa374c7de4 100644 --- a/dlls/user/text.c +++ b/dlls/user/text.c @@ -23,6 +23,8 @@ DEFAULT_DEBUG_CHANNEL(text); +#define countof(a) (sizeof(a)/sizeof(a[0])) + /********************************************************************* * * DrawText functions @@ -291,19 +293,18 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, if (flags & DT_VCENTER) y = rect->top + (rect->bottom - rect->top) / 2 - size.cy / 2; else if (flags & DT_BOTTOM) y = rect->bottom - size.cy; + } - if (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS)) - { - WCHAR swapStr[sizeof(line)]; + if ((flags & DT_SINGLELINE) && size.cx > width && + (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS))) + { + WCHAR swapStr[countof(line)]; WCHAR* fnameDelim = NULL; int totalLen = i_count >= 0 ? i_count : strlenW(str); - - if (size.cx > width) - { int fnameLen = totalLen; /* allow room for '...' */ - count = min(totalLen+3, sizeof(line)-3); + count = min(totalLen+3, countof(line)-3); if (flags & DT_WORD_ELLIPSIS) flags |= DT_WORDBREAK; @@ -374,10 +375,14 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, strncpyW(line, swapStr, len); line[len] = '\0'; strPtr = NULL; - } + if (flags & DT_MODIFYSTRING) strcpyW(str, swapStr); - } + + /* Note that really we ought to refigure the location of + * the underline for the prefix; it might be currently set for + * something we have just ellipsified out. + */ } if (!(flags & DT_CALCRECT)) { -- 2.11.4.GIT