[7/..] gdi32: Fix GetCharacterPlacement for NULL lpResults argument (bug 13094)

Nikolay Sivov bunglehead at gmail.com
Mon May 19 12:03:24 CDT 2008


Changelog:
    - Fix GetCharacterPlacement for NULL lpResults argument (bug 13094)

---
 dlls/gdi32/font.c |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 983d271..cd77020 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -2729,27 +2729,35 @@ GetCharacterPlacementA(HDC hdc, LPCSTR lpString, INT uCount,
     WCHAR *lpStringW;
     INT uCountW;
     GCP_RESULTSW resultsW;
+    GCP_RESULTSW *presults = NULL;
     DWORD ret;
     UINT font_cp;
 
     TRACE("%s, %d, %d, 0x%08x\n",
           debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
 
-    /* both structs are equal in size */
-    memcpy(&resultsW, lpResults, sizeof(resultsW));
+    if(lpResults){
+        /* both structs are equal in size */
+        memcpy(&resultsW, lpResults, sizeof(resultsW));
+
+        if(lpResults->lpOutString)
+            resultsW.lpOutString = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*uCountW);
+
+        presults = &resultsW;
+    }
 
     lpStringW = FONT_mbtowc(hdc, lpString, uCount, &uCountW, &font_cp);
-    if(lpResults->lpOutString)
-        resultsW.lpOutString = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*uCountW);
 
-    ret = GetCharacterPlacementW(hdc, lpStringW, uCountW, nMaxExtent, &resultsW, dwFlags);
+    ret = GetCharacterPlacementW(hdc, lpStringW, uCountW, nMaxExtent, presults, dwFlags);
 
-    lpResults->nGlyphs = resultsW.nGlyphs;
-    lpResults->nMaxFit = resultsW.nMaxFit;
+    if(lpResults){
+        lpResults->nGlyphs = resultsW.nGlyphs;
+        lpResults->nMaxFit = resultsW.nMaxFit;
 
-    if(lpResults->lpOutString) {
-        WideCharToMultiByte(font_cp, 0, resultsW.lpOutString, uCountW,
-                            lpResults->lpOutString, uCount, NULL, NULL );
+        if(lpResults->lpOutString) {
+            WideCharToMultiByte(font_cp, 0, resultsW.lpOutString, uCountW,
+                                lpResults->lpOutString, uCount, NULL, NULL );
+        }
     }
 
     HeapFree(GetProcessHeap(), 0, lpStringW);
@@ -2800,6 +2808,10 @@ GetCharacterPlacementW(
 	    lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit);
 
     if(dwFlags&(~GCP_REORDER))			FIXME("flags 0x%08x ignored\n", dwFlags);
+
+    /* with NULL lpResults return GetTextExtentPoint32 result */
+    if(!lpResults)  goto nullres;
+
     if(lpResults->lpClass)	FIXME("classes not implemented\n");
     if (lpResults->lpCaretPos && (dwFlags & GCP_REORDER))
         FIXME("Caret positions for complex scripts not implemented\n");
@@ -2853,6 +2865,8 @@ GetCharacterPlacementW(
     if(lpResults->lpGlyphs)
 	GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
 
+nullres:
+
     if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
       ret = MAKELONG(size.cx, size.cy);
 
-- 
1.4.4.4






More information about the wine-patches mailing list