From: Christophe CURIS <christophe.cu...@free.fr>

As pointed by Coverity, the 'paintItem' function in the WMBrowser widget
is checking for nullity of its text argument, but before that it called the
strlen function which crashes on NULL pointer. This patch moves the strlen
call to the right place and reduce the lifespan of 'textLen' to highlight
incorrect tries to use the variable.

Signed-off-by: Christophe CURIS <christophe.cu...@free.fr>
---
 WINGs/wbrowser.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c
index 8d1858a..02e906e 100644
--- a/WINGs/wbrowser.c
+++ b/WINGs/wbrowser.c
@@ -478,7 +478,7 @@ static void paintItem(WMList * lPtr, int index, Drawable d, 
char *text, int stat
        Display *display = scr->display;
        WMFont *font = ((state & WLDSIsBranch) ? scr->boldFont : 
scr->normalFont);
        WMColor *backColor = ((state & WLDSSelected) ? scr->white : 
view->backColor);
-       int width, height, x, y, textLen;
+       int width, height, x, y;
 
        /* Parameter not used, but tell the compiler that it is ok */
        (void) index;
@@ -487,13 +487,15 @@ static void paintItem(WMList * lPtr, int index, Drawable 
d, char *text, int stat
        height = rect->size.height;
        x = rect->pos.x;
        y = rect->pos.y;
-       textLen = strlen(text);
 
        XFillRectangle(display, d, WMColorGC(backColor), x, y, width, height);
 
        if (text) {
+               int widthC, textLen;
+
                /* Avoid overlaping... */
-               int widthC = (state & WLDSIsBranch) ? width - 20 : width - 8;
+               widthC = (state & WLDSIsBranch) ? width - 20 : width - 8;
+               textLen = strlen(text);
                if (WMWidthOfString(font, text, textLen) > widthC) {
                        char *textBuf = createTruncatedString(font, text, 
&textLen, widthC);
                        W_PaintText(view, d, font, x + 4, y, widthC, WALeft, 
scr->black, False, textBuf, textLen);
-- 
1.9.2


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to