From: Christophe CURIS <[email protected]>

As pointed by Coverity, there is a small check for NULL pointer when
handling triple-click selection in a WMText, however this check is only
partially implemented so the code would crash later anyway.
This patch implement an appropriate skip to avoid crash, and includes a
log message to help debug if the case happens.

Signed-off-by: Christophe CURIS <[email protected]>
---
 WINGs/wtext.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/WINGs/wtext.c b/WINGs/wtext.c
index 5fcf40c..8641840 100644
--- a/WINGs/wtext.c
+++ b/WINGs/wtext.c
@@ -2150,8 +2150,14 @@ static void autoSelectText(Text * tPtr, int clicks)
        } else if (clicks == 3) {
                TextBlock *cur = tb;
 
-               while (tb && !tb->first) {
+               while (!tb->first) {
                        tb = tb->prior;
+                       if (tb == NULL) {
+#ifndef NDEBUG
+                               wwarning("corrupted list of text blocks in 
WMText, while searching for first block");
+#endif
+                               goto error_select_3clicks;
+                       }
                }
                tPtr->sel.y = tb->sections[0]._y;
 
@@ -2161,6 +2167,7 @@ static void autoSelectText(Text * tPtr, int clicks)
                }
                tPtr->sel.h = tb->sections[tb->nsections - 1]._y + 5 - 
tPtr->sel.y;
 
+       error_select_3clicks:
                tPtr->sel.x = 0;
                tPtr->sel.w = tPtr->docWidth;
                tPtr->clicked.x = 0;    /* only for now, fix sel. code */
-- 
1.9.2


-- 
To unsubscribe, send mail to [email protected].

Reply via email to