From 0c9285bd0f8a29de253efc0f61a6982db0e79206 Mon Sep 17 00:00:00 2001
From: Thomas Faber <thfabba@gmx.de>
Date: Sat, 15 Oct 2011 11:53:49 +0200
Subject: riched20: Prevent setting an invalid default format rect

---
 dlls/riched20/editor.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 5dda1ea..25bad6e 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2611,9 +2611,17 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
 static void ME_SetDefaultFormatRect(ME_TextEditor *editor)
 {
   ITextHost_TxGetClientRect(editor->texthost, &editor->rcFormat);
-  editor->rcFormat.top += editor->exStyleFlags & WS_EX_CLIENTEDGE ? 1 : 0;
-  editor->rcFormat.left += 1 + editor->selofs;
-  editor->rcFormat.right -= 1;
+
+  if (editor->rcFormat.bottom - editor->rcFormat.top > 0)
+    editor->rcFormat.top += editor->exStyleFlags & WS_EX_CLIENTEDGE ? 1 : 0;
+
+  if (editor->rcFormat.right - editor->rcFormat.left >= 2 + editor->selofs)
+  {
+    editor->rcFormat.left += 1 + editor->selofs;
+    editor->rcFormat.right -= 1;
+  }
+  else
+    editor->rcFormat.left = editor->rcFormat.right;
 }
 
 static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
-- 
1.7.3.4
