@@ -4338,19 +4338,23 @@ qf_id2nr(qf_info_T *qi, int_u qfid)
43384338 * If the current list is not "save_qfid" and we can find the list with that ID
43394339 * then make it the current list.
43404340 * This is used when autocommands may have changed the current list.
4341+ * Returns OK if successfully restored the list. Returns FAIL if the list with
4342+ * the specified identifier (save_qfid) is not found in the stack.
43414343 */
4342- static void
4344+ static int
43434345qf_restore_list (qf_info_T * qi , int_u save_qfid )
43444346{
43454347 int curlist ;
43464348
43474349 if (qi -> qf_lists [qi -> qf_curlist ].qf_id != save_qfid )
43484350 {
43494351 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?
4352+ if (curlist < 0 )
4353+ // list is not present
4354+ return FAIL ;
4355+ qi -> qf_curlist = curlist ;
43534356 }
4357+ return OK ;
43544358}
43554359
43564360/*
@@ -4359,9 +4363,10 @@ qf_restore_list(qf_info_T *qi, int_u save_qfid)
43594363 static void
43604364qf_jump_first (qf_info_T * qi , int_u save_qfid , int forceit )
43614365{
4362- qf_restore_list (qi , save_qfid );
4366+ if (qf_restore_list (qi , save_qfid ) == FAIL )
4367+ return ;
43634368
4364- // Autocommands might have cleared the list, check for it
4369+ // Autocommands might have cleared the list, check for that.
43654370 if (!qf_list_empty (qi , qi -> qf_curlist ))
43664371 qf_jump (qi , 0 , 0 , forceit );
43674372}
@@ -5025,7 +5030,8 @@ vgr_qflist_valid(
50255030 }
50265031 }
50275032
5028- qf_restore_list (qi , qfid );
5033+ if (qf_restore_list (qi , qfid ) == FAIL )
5034+ return FALSE;
50295035
50305036 return TRUE;
50315037}
@@ -5371,7 +5377,8 @@ ex_vimgrep(exarg_T *eap)
53715377 if (!qflist_valid (wp , save_qfid ))
53725378 goto theend ;
53735379
5374- qf_restore_list (qi , save_qfid );
5380+ if (qf_restore_list (qi , save_qfid ) == FAIL )
5381+ goto theend ;
53755382
53765383 /* Jump to first match. */
53775384 if (!qf_list_empty (qi , qi -> qf_curlist ))
0 commit comments