Hi Bram!

On Mi, 29 Jul 2015, Bram Moolenaar wrote:

> 
> Christian Brabandt wrote:
> 
> > Bram,
> > attached patch fix some coverity issues.
> > 
> > Issues can be seen, if you open the coverity defect view and search for 
> > the CIDs (you can enter several CIDs in the search field by comma 
> > separating them).
> 
> Thanks, I'll look into this.

Some more fixes.

void_* patches fix that for the mentioned functions the return value is ignored.
cid_*  patches fix the corresponding ID issue from coverity

Best,
Christian
-- 
Hört man eigentlich das Meer rauschen, wenn man sich die bash ans Ohr hält?
                -- stesch auf #LinuxGER

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent 1321bff08ded1303e2541db512bb43e1034dbd71
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -2869,10 +2869,8 @@ do_mouse(oap, c, dir, count, fixindent)
                end_visual.col = leftcol;
            else
                end_visual.col = rightcol;
-           if (curwin->w_cursor.lnum <
+           if (curwin->w_cursor.lnum >=
                                    (start_visual.lnum + end_visual.lnum) / 2)
-               end_visual.lnum = end_visual.lnum;
-           else
                end_visual.lnum = start_visual.lnum;
 
            /* move VIsual to the right column */
# HG changeset patch
# Parent b8dc1e49dacdb533c27e06f71f0e496068b15b18
diff --git a/src/window.c b/src/window.c
--- a/src/window.c
+++ b/src/window.c
@@ -2585,8 +2585,10 @@ win_close_othertab(win, free_buf, tp)
     if (wp == NULL)
        return;
 
-    /* When closing the last window in a tab page remove the tab page. */
-    if (tp == NULL ? firstwin == lastwin : tp->tp_firstwin == tp->tp_lastwin)
+    /* When closing the last window in a tab page remove the tab page.
+     * tp can't be NULL here */
+
+    if (tp->tp_firstwin == tp->tp_lastwin)
     {
        if (tp == first_tabpage)
            first_tabpage = tp->tp_next;
# HG changeset patch
# Parent 4af6d3d0f1a001a8290913c435b624a845eeec30
diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c
--- a/src/if_xcmdsrv.c
+++ b/src/if_xcmdsrv.c
@@ -1351,15 +1351,10 @@ serverEventProc(dpy, eventPtr)
                    continue;
 
                pcPtr->code = code;
-               if (res != NULL)
-               {
-                   res = serverConvert(enc, res, &tofree);
-                   if (tofree == NULL)
-                       res = vim_strsave(res);
-                   pcPtr->result = res;
-               }
-               else
-                   pcPtr->result = vim_strsave((char_u *)"");
+               res = serverConvert(enc, res, &tofree);
+               if (tofree == NULL)
+                   res = vim_strsave(res);
+               pcPtr->result = res;
                break;
            }
        }
# HG changeset patch
# Parent 97ebb810ef0ecb602f028c837d526a40b550b910
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -3051,7 +3051,7 @@ fopen_noinh_readbin(filename)
     {
        int fdflags = fcntl(fd_tmp, F_GETFD);
        if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
-           fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC);
+           (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC);
     }
 # endif
 
# HG changeset patch
# Parent 66ab912f4de5d3f864cce4ef86792c5e96b9a444
diff --git a/src/if_cscope.c b/src/if_cscope.c
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -2089,6 +2089,8 @@ cs_print_tags_priv(matches, cntxts, num_
     strcpy(tbuf, matches[0]);
     ptag = strtok(tbuf, "\t");
 
+    if (ptag == NULL)
+       return;
     newsize = (int)(strlen(cstag_msg) + strlen(ptag));
     buf = (char *)alloc(newsize);
     if (buf != NULL)
# HG changeset patch
# Parent cbfae2243b94e54b07215748beea30cbe23933b4
diff --git a/src/os_unix.c b/src/os_unix.c
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -7000,7 +7000,6 @@ do_xterm_trace()
 
        /* Rely on the same mouse code for the duration of this */
        mouse_code = find_termcode(mouse_name);
-       prev_row = mouse_row;
        prev_row = mouse_col;
        xterm_trace = 2;
 
Fix Coverity issue: 1307835
# HG changeset patch
# Parent aa5c55c7db7159b15511be8a8eb943956246cf7b
diff --git a/src/if_cscope.c b/src/if_cscope.c
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -1214,7 +1214,10 @@ cs_find_common(opt, pat, forceit, verbos
 
     nummatches = (int *)alloc(sizeof(int)*csinfo_size);
     if (nummatches == NULL)
+    {
+       vim_free(cmd);
        return FALSE;
+    }
 
     /* Send query to all open connections, then count the total number
      * of matches so we can alloc all in one swell foop. */
# HG changeset patch
# Parent 2d21a6f04eaea786c015cf2e412210c68022fb9b
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -6856,7 +6856,8 @@ helptags_one(dir, ext, tagfname, add_hel
        /*
         * Sort the tags.
         */
-       sort_strings((char_u **)ga.ga_data, ga.ga_len);
+       if (ga.ga_data != NULL)
+           sort_strings((char_u **)ga.ga_data, ga.ga_len);
 
        /*
         * Check for duplicates.
# HG changeset patch
# Parent 08563e624eefc4e910a3eb879ca4e9bb5c2ed686
diff --git a/src/if_cscope.c b/src/if_cscope.c
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -1292,7 +1292,7 @@ cs_find_common(opt, pat, forceit, verbos
 # ifdef FEAT_WINDOWS
                if (postponed_split != 0)
                {
-                   win_split(postponed_split > 0 ? postponed_split : 0,
+                   (void)win_split(postponed_split > 0 ? postponed_split : 0,
                                                       postponed_split_flags);
                    RESET_BINDING(curwin);
                    postponed_split = 0;
Fixes coverity issues 99204, 99205
# HG changeset patch
# Parent f89d4d00504ef86f20b5c0d039446ae15dec99ed
diff --git a/src/window.c b/src/window.c
--- a/src/window.c
+++ b/src/window.c
@@ -141,7 +141,7 @@ do_window(nchar, Prenum, xchar)
 #ifdef FEAT_GUI
                need_mouse_correct = TRUE;
 #endif
-               win_split((int)Prenum, 0);
+               (void)win_split((int)Prenum, 0);
                break;
 
 #ifdef FEAT_VERTSPLIT
@@ -159,7 +159,7 @@ do_window(nchar, Prenum, xchar)
 # ifdef FEAT_GUI
                need_mouse_correct = TRUE;
 # endif
-               win_split((int)Prenum, WSP_VERT);
+               (void)win_split((int)Prenum, WSP_VERT);
                break;
 #endif
 
Fixes Coverity CID 99196, 99197, 99197, 99198, 99208
# HG changeset patch
# Parent f89d4d00504ef86f20b5c0d039446ae15dec99ed
diff --git a/src/move.c b/src/move.c
--- a/src/move.c
+++ b/src/move.c
@@ -1512,7 +1512,7 @@ scrolldown_clamp()
        --curwin->w_topline;
 #endif
 #ifdef FEAT_FOLDING
-       hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+       (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
 #endif
        --curwin->w_botline;        /* approximate w_botline */
        curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -3802,8 +3802,8 @@ clear_showcmd()
        }
 # ifdef FEAT_FOLDING
        /* Include closed folds as a whole. */
-       hasFolding(top, &top, NULL);
-       hasFolding(bot, NULL, &bot);
+       (void)hasFolding(top, &top, NULL);
+       (void)hasFolding(bot, NULL, &bot);
 # endif
        lines = bot - top + 1;
 
@@ -5947,7 +5947,7 @@ nv_scroll(cap)
                lnum = curwin->w_topline;
                while (n-- > 0 && lnum < curwin->w_botline - 1)
                {
-                   hasFolding(lnum, NULL, &lnum);
+                   (void)hasFolding(lnum, NULL, &lnum);
                    ++lnum;
                }
                n = lnum - curwin->w_topline;
diff --git a/src/ui.c b/src/ui.c
--- a/src/ui.c
+++ b/src/ui.c
@@ -2903,7 +2903,7 @@ retnomove:
                    break;
                first = FALSE;
 #ifdef FEAT_FOLDING
-               hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+               (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
 #endif
 #ifdef FEAT_DIFF
                if (curwin->w_topfill < diff_check(curwin, curwin->w_topline))
Fixes Coverity Issue: CID_99201
# HG changeset patch
# Parent 6a302a48bdae579db5676433d6af52ae25e2c99e
diff --git a/src/gui.c b/src/gui.c
--- a/src/gui.c
+++ b/src/gui.c
@@ -1575,7 +1575,7 @@ gui_set_shellsize(mustset, fit_to_displa
     base_height = gui_get_base_height();
     if (fit_to_display)
        /* Remember the original window position. */
-       gui_mch_get_winpos(&x, &y);
+       (void)gui_mch_get_winpos(&x, &y);
 
 #ifdef USE_SUN_WORKSHOP
     if (!mustset && usingSunWorkShop
diff --git a/src/gui_w16.c b/src/gui_w16.c
--- a/src/gui_w16.c
+++ b/src/gui_w16.c
@@ -282,7 +282,7 @@ gui_mswin_get_menu_height(
            result = MyWindowProc(hwnd, uMsg, wParam, lParam);
            if (result == HTCLIENT)
            {
-               gui_mch_get_winpos(&x, &y);
+               (void)gui_mch_get_winpos(&x, &y);
                xPos -= x;
 
                if (xPos < 48) /*<VN> TODO should use system metric?*/
diff --git a/src/gui_w32.c b/src/gui_w32.c
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1227,7 +1227,7 @@ set_tabline_font(void)
                        return result;
                }
 #endif
-               gui_mch_get_winpos(&x, &y);
+               (void)gui_mch_get_winpos(&x, &y);
                xPos -= x;
 
                if (xPos < 48) /* <VN> TODO should use system metric? */
Fix Coverity issue CID_1307802

# HG changeset patch
# Parent 66ab912f4de5d3f864cce4ef86792c5e96b9a444
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -6734,7 +6734,7 @@ list_join_inner(gap, l, sep, echo_style,
        len = (int)STRLEN(s);
        sumlen += len;
 
-       ga_grow(join_gap, 1);
+       (void)ga_grow(join_gap, 1);
        p = ((join_T *)join_gap->ga_data) + (join_gap->ga_len++);
        if (tofree != NULL || s != numbuf)
        {
@@ -19526,7 +19526,7 @@ error:
                    goto error;
            }
 
-           ga_grow(&ga, cplen);
+           (void)ga_grow(&ga, cplen);
            mch_memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
            ga.ga_len += cplen;
 
@@ -19546,7 +19546,7 @@ error:
     }
 
     /* add a terminating NUL */
-    ga_grow(&ga, 1);
+    (void)ga_grow(&ga, 1);
     ga_append(&ga, NUL);
 
     rettv->vval.v_string = ga.ga_data;
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -3841,7 +3841,7 @@ script_line_start()
     {
        /* Grow the array before starting the timer, so that the time spent
         * here isn't counted. */
-       ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len));
+       (void)ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - 
si->sn_prl_ga.ga_len));
        si->sn_prl_idx = sourcing_lnum - 1;
        while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
                && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen)
diff --git a/src/ex_getln.c b/src/ex_getln.c
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -2312,7 +2312,7 @@ getexmodeline(promptc, cookie, indent)
 add_indent:
                while (get_indent_str(p, 8, FALSE) < indent)
                {
-                   ga_grow(&line_ga, 2);  /* one more for the NUL */
+                   (void)ga_grow(&line_ga, 2);  /* one more for the NUL */
                    p = (char_u *)line_ga.ga_data;
                    s = skipwhite(p);
                    mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1);
diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c
--- a/src/if_xcmdsrv.c
+++ b/src/if_xcmdsrv.c
@@ -1265,12 +1265,12 @@ serverEventProc(dpy, eventPtr)
                        /* Initialize the result property. */
                        ga_init2(&reply, 1, 100);
 #ifdef FEAT_MBYTE
-                       ga_grow(&reply, 50 + STRLEN(p_enc));
+                       (void)ga_grow(&reply, 50 + STRLEN(p_enc));
                        sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ",
                                                   0, 0, p_enc, 0, serial, 0);
                        reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial);
 #else
-                       ga_grow(&reply, 50);
+                       (void)ga_grow(&reply, 50);
                        sprintf(reply.ga_data, "%cr%c-s %s%c-r ",
                                                             0, 0, serial, 0);
                        reply.ga_len = 10 + STRLEN(serial);
diff --git a/src/regexp.c b/src/regexp.c
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -3825,14 +3825,14 @@ bt_regexec_both(line, col, tm)
        /* Use an item size of 1 byte, since we push different things
         * onto the regstack. */
        ga_init2(&regstack, 1, REGSTACK_INITIAL);
-       ga_grow(&regstack, REGSTACK_INITIAL);
+       (void)ga_grow(&regstack, REGSTACK_INITIAL);
        regstack.ga_growsize = REGSTACK_INITIAL * 8;
     }
 
     if (backpos.ga_data == NULL)
     {
        ga_init2(&backpos, sizeof(backpos_T), BACKPOS_INITIAL);
-       ga_grow(&backpos, BACKPOS_INITIAL);
+       (void)ga_grow(&backpos, BACKPOS_INITIAL);
        backpos.ga_growsize = BACKPOS_INITIAL * 8;
     }
 
diff --git a/src/syntax.c b/src/syntax.c
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -6670,7 +6670,7 @@ syntime_report()
        spp = &(SYN_ITEMS(curwin->w_s)[idx]);
        if (spp->sp_time.count > 0)
        {
-           ga_grow(&ga, 1);
+           (void)ga_grow(&ga, 1);
            p = ((time_entry_T *)ga.ga_data) + ga.ga_len;
            p->total = spp->sp_time.total;
            profile_add(&total_total, &spp->sp_time.total);
Fixes Coverity Issue: 99195
# HG changeset patch
# Parent 1321bff08ded1303e2541db512bb43e1034dbd71
diff --git a/src/fold.c b/src/fold.c
--- a/src/fold.c
+++ b/src/fold.c
@@ -2446,7 +2446,7 @@ foldUpdateIEMSRecurse(gap, level, startl
     if (getlevel == foldlevelMarker && flp->start <= flp->lvl - level
                                                              && flp->lvl > 0)
     {
-       foldFind(gap, startlnum - 1, &fp);
+       (void)foldFind(gap, startlnum - 1, &fp);
        if (fp >= ((fold_T *)gap->ga_data) + gap->ga_len
                                                   || fp->fd_top >= startlnum)
            fp = NULL;
@@ -2508,7 +2508,7 @@ foldUpdateIEMSRecurse(gap, level, startl
            }
            if (lvl < level + i)
            {
-               foldFind(&fp->fd_nested, flp->lnum - fp->fd_top, &fp2);
+               (void)foldFind(&fp->fd_nested, flp->lnum - fp->fd_top, &fp2);
                if (fp2 != NULL)
                    bot = fp2->fd_top + fp2->fd_len - 1 + fp->fd_top;
            }
Fixes coverity issue CID_99206

# HG changeset patch
# Parent 66ab912f4de5d3f864cce4ef86792c5e96b9a444
diff --git a/src/gui.c b/src/gui.c
--- a/src/gui.c
+++ b/src/gui.c
@@ -5366,7 +5366,7 @@ gui_do_findrepl(flags, find_text, repl_t
     {
        /* Search for the next match. */
        i = msg_scroll;
-       do_search(NULL, down ? '/' : '?', ga.ga_data, 1L,
+       (void)do_search(NULL, down ? '/' : '?', ga.ga_data, 1L,
                                              SEARCH_MSG + SEARCH_MARK, NULL);
        msg_scroll = i;     /* don't let an error message set msg_scroll */
     }
Fixes Coverity issue 99207

# HG changeset patch
# Parent f89d4d00504ef86f20b5c0d039446ae15dec99ed
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -6247,7 +6247,7 @@ nv_gotofile(cap)
     {
        /* do autowrite if necessary */
        if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !P_HID(curbuf))
-           autowrite(curbuf, FALSE);
+           (void)autowrite(curbuf, FALSE);
        setpcmark();
        (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
                                       P_HID(curbuf) ? ECMD_HIDE : 0, curwin);

Raspunde prin e-mail lui