To: vim_dev@googlegroups.com Subject: Patch 8.1.0455 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0455 Problem: Checking for empty quickfix stack is not consistent. Solution: Use qf_stack_empty(). (Yegappan Lakshmanan) Files: src/quickfix.c *** ../vim-8.1.0454/src/quickfix.c 2018-09-28 23:09:50.558463030 +0200 --- src/quickfix.c 2018-10-07 14:34:59.832140408 +0200 *************** *** 1499,1504 **** --- 1499,1513 ---- } /* + * Returns TRUE if the specified quickfix/location stack is empty + */ + static int + qf_stack_empty(qf_info_T *qi) + { + return qi == NULL || qi->qf_listcount <= 0; + } + + /* * Returns TRUE if the specified quickfix/location list is empty. */ static int *************** *** 3220,3227 **** if (qi == NULL) qi = &ql_info; ! if (qi->qf_curlist >= qi->qf_listcount ! || qf_list_empty(qi, qi->qf_curlist)) { EMSG(_(e_quickfix)); return; --- 3229,3235 ---- if (qi == NULL) qi = &ql_info; ! if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) { EMSG(_(e_quickfix)); return; *************** *** 3412,3419 **** } } ! if (qi->qf_curlist >= qi->qf_listcount ! || qf_list_empty(qi, qi->qf_curlist)) { EMSG(_(e_quickfix)); return; --- 3420,3426 ---- } } ! if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) { EMSG(_(e_quickfix)); return; *************** *** 3601,3608 **** if (is_loclist_cmd(eap->cmdidx)) qi = GET_LOC_LIST(curwin); ! if (qi == NULL || (qi->qf_listcount == 0 ! && qf_list_empty(qi, qi->qf_curlist))) MSG(_("No entries")); else for (i = 0; i < qi->qf_listcount; ++i) --- 3608,3614 ---- if (is_loclist_cmd(eap->cmdidx)) qi = GET_LOC_LIST(curwin); ! if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) MSG(_("No entries")); else for (i = 0; i < qi->qf_listcount; ++i) *************** *** 3830,3838 **** * close the window. If a quickfix window is not open, then open * it if we have errors; otherwise, leave it closed. */ ! if (qi->qf_lists[qi->qf_curlist].qf_nonevalid ! || qf_list_empty(qi, qi->qf_curlist) ! || qi->qf_curlist >= qi->qf_listcount) { if (win != NULL) ex_cclose(eap); --- 3836,3844 ---- * close the window. If a quickfix window is not open, then open * it if we have errors; otherwise, leave it closed. */ ! if (qf_stack_empty(qi) ! || qi->qf_lists[qi->qf_curlist].qf_nonevalid ! || qf_list_empty(qi, qi->qf_curlist)) { if (win != NULL) ex_cclose(eap); *************** *** 4342,4348 **** } /* Check if there is anything to display */ ! if (qi->qf_curlist < qi->qf_listcount) { char_u dirname[MAXPATHL]; --- 4348,4354 ---- } /* Check if there is anything to display */ ! if (!qf_stack_empty(qi)) { char_u dirname[MAXPATHL]; *************** *** 5333,5339 **** if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) ! || qi->qf_curlist == qi->qf_listcount) /* make place for a new list */ qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep)); --- 5339,5345 ---- if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) ! || qf_stack_empty(qi)) /* make place for a new list */ qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep)); *************** *** 6107,6117 **** flags = qf_getprop_keys2flags(what, (wp != NULL)); ! if (qi != NULL && qi->qf_listcount != 0) qf_idx = qf_getprop_qfidx(qi, what); /* List is not present or is empty */ ! if (qi == NULL || qi->qf_listcount == 0 || qf_idx == INVALID_QFIDX) return qf_getprop_defaults(qi, flags, retdict); qfl = &qi->qf_lists[qf_idx]; --- 6113,6123 ---- flags = qf_getprop_keys2flags(what, (wp != NULL)); ! if (!qf_stack_empty(qi)) qf_idx = qf_getprop_qfidx(qi, what); /* List is not present or is empty */ ! if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) return qf_getprop_defaults(qi, flags, retdict); qfl = &qi->qf_lists[qf_idx]; *************** *** 6313,6319 **** * stack. */ *newlist = TRUE; ! qf_idx = qi->qf_listcount > 0 ? qi->qf_listcount - 1 : 0; } else if (qf_idx < 0 || qf_idx >= qi->qf_listcount) return INVALID_QFIDX; --- 6319,6325 ---- * stack. */ *newlist = TRUE; ! qf_idx = qf_stack_empty(qi) ? 0 : qi->qf_listcount - 1; } else if (qf_idx < 0 || qf_idx >= qi->qf_listcount) return INVALID_QFIDX; *************** *** 6324,6330 **** && di->di_tv.vval.v_string != NULL && STRCMP(di->di_tv.vval.v_string, "$") == 0) { ! if (qi->qf_listcount > 0) qf_idx = qi->qf_listcount - 1; else if (*newlist) qf_idx = 0; --- 6330,6336 ---- && di->di_tv.vval.v_string != NULL && STRCMP(di->di_tv.vval.v_string, "$") == 0) { ! if (!qf_stack_empty(qi)) qf_idx = qi->qf_listcount - 1; else if (*newlist) qf_idx = 0; *************** *** 6452,6458 **** int qf_idx; int newlist = FALSE; ! if (action == ' ' || qi->qf_curlist == qi->qf_listcount) newlist = TRUE; qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist); --- 6458,6464 ---- int qf_idx; int newlist = FALSE; ! if (action == ' ' || qf_stack_empty(qi)) newlist = TRUE; qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist); *** ../vim-8.1.0454/src/version.c 2018-10-06 15:43:13.062876189 +0200 --- src/version.c 2018-10-07 14:36:35.659323843 +0200 *************** *** 794,795 **** --- 794,797 ---- { /* Add new patch number below this line */ + /**/ + 455, /**/ -- hundred-and-one symptoms of being an internet addict: 165. You have a web page burned into your glasses /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///