From 42febe3cecf0c5885cbf261ed34292572276277b Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 18 May 2014 21:31:41 +0200 Subject: [PATCH] WINGs: fix check for NULL pointer in WMText selection (Coverity #50067) 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 --- WINGs/wtext.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WINGs/wtext.c b/WINGs/wtext.c index 5fcf40cc..86418407 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 */