comparison src/quickfix.c @ 14495:178162aeebeb v8.1.0261

patch 8.1.0261: Coverity complains about a negative array index commit https://github.com/vim/vim/commit/38efd1d17a6e6aa2add71efdf2cde4a788e5f5e5 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 9 21:52:24 2018 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Thu, 09 Aug 2018 22:00:06 +0200
parents 9df0fcbfebb2
children 5a10a0020c3e
comparison
equal deleted inserted replaced
14494:6bc01ddb6932 14495:178162aeebeb
2009 static qf_info_T * 2009 static qf_info_T *
2010 ll_new_list(void) 2010 ll_new_list(void)
2011 { 2011 {
2012 qf_info_T *qi; 2012 qf_info_T *qi;
2013 2013
2014 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T)); 2014 qi = (qf_info_T *)alloc_clear((unsigned)sizeof(qf_info_T));
2015 if (qi != NULL) 2015 if (qi != NULL)
2016 {
2017 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
2018 qi->qf_refcount++; 2016 qi->qf_refcount++;
2019 }
2020
2021 return qi; 2017 return qi;
2022 } 2018 }
2023 2019
2024 /* 2020 /*
2025 * Return the location list for window 'wp'. 2021 * Return the location list for window 'wp'.
4337 return qf_idx; 4333 return qf_idx;
4338 return INVALID_QFIDX; 4334 return INVALID_QFIDX;
4339 } 4335 }
4340 4336
4341 /* 4337 /*
4338 * If the current list is not "save_qfid" and we can find the list with that ID
4339 * then make it the current list.
4340 * This is used when autocommands may have changed the current list.
4341 */
4342 static void
4343 qf_restore_list(qf_info_T *qi, int_u save_qfid)
4344 {
4345 int curlist;
4346
4347 if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
4348 {
4349 curlist = qf_id2nr(qi, save_qfid);
4350 if (curlist >= 0)
4351 qi->qf_curlist = curlist;
4352 // else: what if the list can't be found?
4353 }
4354 }
4355
4356 /*
4342 * Jump to the first entry if there is one. 4357 * Jump to the first entry if there is one.
4343 */ 4358 */
4344 static void 4359 static void
4345 qf_jump_first(qf_info_T *qi, int_u save_qfid, int forceit) 4360 qf_jump_first(qf_info_T *qi, int_u save_qfid, int forceit)
4346 { 4361 {
4347 // If autocommands changed the current list, then restore it 4362 qf_restore_list(qi, save_qfid);
4348 if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
4349 qi->qf_curlist = qf_id2nr(qi, save_qfid);
4350 4363
4351 // Autocommands might have cleared the list, check for it 4364 // Autocommands might have cleared the list, check for it
4352 if (!qf_list_empty(qi, qi->qf_curlist)) 4365 if (!qf_list_empty(qi, qi->qf_curlist))
4353 qf_jump(qi, 0, 0, forceit); 4366 qf_jump(qi, 0, 0, forceit);
4354 } 4367 }
5010 qf_new_list(qi, title); 5023 qf_new_list(qi, title);
5011 return TRUE; 5024 return TRUE;
5012 } 5025 }
5013 } 5026 }
5014 5027
5015 if (qi->qf_lists[qi->qf_curlist].qf_id != qfid) 5028 qf_restore_list(qi, qfid);
5016 /* Autocommands changed the quickfix list. Find the one we were
5017 * using and restore it. */
5018 qi->qf_curlist = qf_id2nr(qi, qfid);
5019 5029
5020 return TRUE; 5030 return TRUE;
5021 } 5031 }
5022 5032
5023 /* 5033 /*
5359 * is still valid. 5369 * is still valid.
5360 */ 5370 */
5361 if (!qflist_valid(wp, save_qfid)) 5371 if (!qflist_valid(wp, save_qfid))
5362 goto theend; 5372 goto theend;
5363 5373
5364 // If autocommands changed the current list, then restore it 5374 qf_restore_list(qi, save_qfid);
5365 if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
5366 qi->qf_curlist = qf_id2nr(qi, save_qfid);
5367 5375
5368 /* Jump to first match. */ 5376 /* Jump to first match. */
5369 if (!qf_list_empty(qi, qi->qf_curlist)) 5377 if (!qf_list_empty(qi, qi->qf_curlist))
5370 { 5378 {
5371 if ((flags & VGR_NOJUMP) == 0) 5379 if ((flags & VGR_NOJUMP) == 0)
5682 5690
5683 l = list_alloc(); 5691 l = list_alloc();
5684 if (l == NULL) 5692 if (l == NULL)
5685 return FAIL; 5693 return FAIL;
5686 5694
5687 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T)); 5695 qi = ll_new_list();
5688 if (qi != NULL) 5696 if (qi != NULL)
5689 { 5697 {
5690 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
5691 qi->qf_refcount++;
5692
5693 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, 5698 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
5694 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) 5699 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
5695 { 5700 {
5696 (void)get_errorlist(qi, NULL, 0, l); 5701 (void)get_errorlist(qi, NULL, 0, l);
5697 qf_free(qi, 0); 5702 qf_free(qi, 0);