@@ -2011,13 +2011,9 @@ ll_new_list(void)
20112011{
20122012 qf_info_T * qi ;
20132013
2014- qi = (qf_info_T * )alloc ((unsigned )sizeof (qf_info_T ));
2014+ qi = (qf_info_T * )alloc_clear ((unsigned )sizeof (qf_info_T ));
20152015 if (qi != NULL )
2016- {
2017- vim_memset (qi , 0 , (size_t )(sizeof (qf_info_T )));
20182016 qi -> qf_refcount ++ ;
2019- }
2020-
20212017 return qi ;
20222018}
20232019
@@ -4338,15 +4334,32 @@ qf_id2nr(qf_info_T *qi, int_u qfid)
43384334 return INVALID_QFIDX ;
43394335}
43404336
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+
43414356/*
43424357 * Jump to the first entry if there is one.
43434358 */
43444359 static void
43454360qf_jump_first (qf_info_T * qi , int_u save_qfid , int forceit )
43464361{
4347- // If autocommands changed the current list, then restore it
4348- if (qi -> qf_lists [qi -> qf_curlist ].qf_id != save_qfid )
4349- qi -> qf_curlist = qf_id2nr (qi , save_qfid );
4362+ qf_restore_list (qi , save_qfid );
43504363
43514364 // Autocommands might have cleared the list, check for it
43524365 if (!qf_list_empty (qi , qi -> qf_curlist ))
@@ -5012,10 +5025,7 @@ vgr_qflist_valid(
50125025 }
50135026 }
50145027
5015- if (qi -> qf_lists [qi -> qf_curlist ].qf_id != 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 );
5028+ qf_restore_list (qi , qfid );
50195029
50205030 return TRUE;
50215031}
@@ -5361,9 +5371,7 @@ ex_vimgrep(exarg_T *eap)
53615371 if (!qflist_valid (wp , save_qfid ))
53625372 goto theend ;
53635373
5364- // If autocommands changed the current list, then restore it
5365- if (qi -> qf_lists [qi -> qf_curlist ].qf_id != save_qfid )
5366- qi -> qf_curlist = qf_id2nr (qi , save_qfid );
5374+ qf_restore_list (qi , save_qfid );
53675375
53685376 /* Jump to first match. */
53695377 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)
56845692 if (l == NULL )
56855693 return FAIL ;
56865694
5687- qi = ( qf_info_T * ) alloc (( unsigned ) sizeof ( qf_info_T ) );
5695+ qi = ll_new_list ( );
56885696 if (qi != NULL )
56895697 {
5690- vim_memset (qi , 0 , (size_t )(sizeof (qf_info_T )));
5691- qi -> qf_refcount ++ ;
5692-
56935698 if (qf_init_ext (qi , 0 , NULL , NULL , & di -> di_tv , errorformat ,
56945699 TRUE, (linenr_T )0 , (linenr_T )0 , NULL , NULL ) > 0 )
56955700 {
0 commit comments