From 5b46372b7cc36f07d61bce63d5e3ae8aa766aa5a Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Sat, 5 Dec 2015 15:31:06 +1100
Subject: d3dx9_36: ID3DXFont_DrawText calc_rect can be null

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
---
 dlls/d3dx9_36/font.c       |  8 ++++++--
 dlls/d3dx9_36/tests/core.c | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c
index 63aa828..2262db9 100644
--- a/dlls/d3dx9_36/font.c
+++ b/dlls/d3dx9_36/font.c
@@ -236,7 +236,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
         const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
 {
     struct d3dx_font *This = impl_from_ID3DXFont(iface);
-    RECT calc_rect = *rect;
+    RECT calc_rect;
     INT height;
 
     TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x\n",
@@ -252,11 +252,15 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
     while (count > 0 && !string[count-1])
         count--;
 
+    if (rect)
+        calc_rect = *rect;
+
     height = DrawTextW(This->hdc, string, count, &calc_rect, format | DT_CALCRECT);
 
     if (format & DT_CALCRECT)
     {
-        *rect = calc_rect;
+        if (rect)
+            *rect = calc_rect;
         return height;
     }
 
diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c
index c931260..1cf0db6 100644
--- a/dlls/d3dx9_36/tests/core.c
+++ b/dlls/d3dx9_36/tests/core.c
@@ -616,6 +616,15 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
         height = ID3DXFont_DrawTextA(font, NULL, testA, 2, &rect, 0, 0xFF00FF);
         ok(height == 12, "DrawTextA returned %d, expected 12.\n", height);
 
+        height = ID3DXFont_DrawTextA(font, NULL, testA, -1, NULL, 0, 0xFF00FF);
+        ok(height == 12, "DrawTextA returned %d, expected 12.\n", height);
+
+        height = ID3DXFont_DrawTextA(font, NULL, testA, -1, NULL, DT_CALCRECT, 0xFF00FF);
+        ok(height == 12, "DrawTextA returned %d, expected 12.\n", height);
+
+        height = ID3DXFont_DrawTextA(font, NULL, NULL, -1, NULL, 0, 0xFF00FF);
+        ok(height == 0, "DrawTextA returned %d, expected 0.\n", height);
+
 if (0) { /* Causes a lockup on windows 7. */
         height = ID3DXFont_DrawTextW(font, NULL, testW, -2, &rect, 0, 0xFF00FF);
         ok(height == 12, "DrawTextW returned %d, expected 12.\n", height);
@@ -633,6 +642,15 @@ if (0) { /* Causes a lockup on windows 7. */
         height = ID3DXFont_DrawTextW(font, NULL, testW, 2, &rect, 0, 0xFF00FF);
         ok(height == 12, "DrawTextW returned %d, expected 12.\n", height);
 
+        height = ID3DXFont_DrawTextW(font, NULL, testW, -1, NULL, 0, 0xFF00FF);
+        ok(height == 12, "DrawTextA returned %d, expected 12.\n", height);
+
+        height = ID3DXFont_DrawTextW(font, NULL, testW, -1, NULL, DT_CALCRECT, 0xFF00FF);
+        ok(height == 12, "DrawTextA returned %d, expected 12.\n", height);
+
+        height = ID3DXFont_DrawTextW(font, NULL, NULL, -1, NULL, 0, 0xFF00FF);
+        ok(height == 0, "DrawTextA returned %d, expected 0.\n", height);
+
         ID3DXFont_Release(font);
     }
 }
-- 
2.6.2

