forked from aniani/vim
patch 8.1.0261: Coverity complains about a negative array index
Problem: Coverity complains about a negative array index. Solution: When qf_id2nr() cannot find the list then don't set qf_curlist.
This commit is contained in:
parent
4d37557ac6
commit
38efd1d17a
@ -2011,13 +2011,9 @@ ll_new_list(void)
|
|||||||
{
|
{
|
||||||
qf_info_T *qi;
|
qf_info_T *qi;
|
||||||
|
|
||||||
qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
|
qi = (qf_info_T *)alloc_clear((unsigned)sizeof(qf_info_T));
|
||||||
if (qi != NULL)
|
if (qi != NULL)
|
||||||
{
|
|
||||||
vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
|
|
||||||
qi->qf_refcount++;
|
qi->qf_refcount++;
|
||||||
}
|
|
||||||
|
|
||||||
return qi;
|
return qi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4338,15 +4334,32 @@ qf_id2nr(qf_info_T *qi, int_u qfid)
|
|||||||
return INVALID_QFIDX;
|
return INVALID_QFIDX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the current list is not "save_qfid" and we can find the list with that ID
|
||||||
|
* then make it the current list.
|
||||||
|
* This is used when autocommands may have changed the current list.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
qf_restore_list(qf_info_T *qi, int_u save_qfid)
|
||||||
|
{
|
||||||
|
int curlist;
|
||||||
|
|
||||||
|
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
|
||||||
|
{
|
||||||
|
curlist = qf_id2nr(qi, save_qfid);
|
||||||
|
if (curlist >= 0)
|
||||||
|
qi->qf_curlist = curlist;
|
||||||
|
// else: what if the list can't be found?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Jump to the first entry if there is one.
|
* Jump to the first entry if there is one.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
qf_jump_first(qf_info_T *qi, int_u save_qfid, int forceit)
|
qf_jump_first(qf_info_T *qi, int_u save_qfid, int forceit)
|
||||||
{
|
{
|
||||||
// If autocommands changed the current list, then restore it
|
qf_restore_list(qi, save_qfid);
|
||||||
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
|
|
||||||
qi->qf_curlist = qf_id2nr(qi, save_qfid);
|
|
||||||
|
|
||||||
// Autocommands might have cleared the list, check for it
|
// Autocommands might have cleared the list, check for it
|
||||||
if (!qf_list_empty(qi, qi->qf_curlist))
|
if (!qf_list_empty(qi, qi->qf_curlist))
|
||||||
@ -5012,10 +5025,7 @@ vgr_qflist_valid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qi->qf_lists[qi->qf_curlist].qf_id != qfid)
|
qf_restore_list(qi, qfid);
|
||||||
/* Autocommands changed the quickfix list. Find the one we were
|
|
||||||
* using and restore it. */
|
|
||||||
qi->qf_curlist = qf_id2nr(qi, qfid);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -5361,9 +5371,7 @@ ex_vimgrep(exarg_T *eap)
|
|||||||
if (!qflist_valid(wp, save_qfid))
|
if (!qflist_valid(wp, save_qfid))
|
||||||
goto theend;
|
goto theend;
|
||||||
|
|
||||||
// If autocommands changed the current list, then restore it
|
qf_restore_list(qi, save_qfid);
|
||||||
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
|
|
||||||
qi->qf_curlist = qf_id2nr(qi, save_qfid);
|
|
||||||
|
|
||||||
/* Jump to first match. */
|
/* Jump to first match. */
|
||||||
if (!qf_list_empty(qi, qi->qf_curlist))
|
if (!qf_list_empty(qi, qi->qf_curlist))
|
||||||
@ -5684,12 +5692,9 @@ qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
|
|||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
|
qi = ll_new_list();
|
||||||
if (qi != NULL)
|
if (qi != NULL)
|
||||||
{
|
{
|
||||||
vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
|
|
||||||
qi->qf_refcount++;
|
|
||||||
|
|
||||||
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
|
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
|
||||||
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
|
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
|
||||||
{
|
{
|
||||||
|
@ -794,6 +794,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
261,
|
||||||
/**/
|
/**/
|
||||||
260,
|
260,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user