To: vim_dev@googlegroups.com Subject: Patch 8.2.4496 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4496 (after 8.2.4494) Problem: Coverity gives warnings after tags code refactoring. Solution: Avoid the warnings. (Yegappan Lakshmanan, closes #9882) Files: src/tag.c *** ../vim-8.2.4495/src/tag.c 2022-03-02 20:29:31.610116664 +0000 --- src/tag.c 2022-03-03 10:38:24.302425556 +0000 *************** *** 1580,1585 **** --- 1580,1586 ---- * State information used during a tag search */ typedef struct { + char_u *tag_fname; // name of tag file pat_T orgpat; // holds unconverted pattern info #ifdef FEAT_MULTI_LANG char_u *help_lang_find; // lang to be found *************** *** 1610,1615 **** --- 1611,1617 ---- { int mtt; + st->tag_fname = alloc(MAXPATHL + 1); st->orgpat.pat = pat; st->orgpat.len = (int)STRLEN(pat); st->orgpat.regmatch.regprog = NULL; *************** *** 1634,1640 **** } // check for out of memory situation ! if (st->lbuf == NULL #ifdef FEAT_EMACS_TAGS || st->ebuf == NULL #endif --- 1636,1643 ---- } // check for out of memory situation ! if (st->tag_fname == NULL ! || st->lbuf == NULL #ifdef FEAT_EMACS_TAGS || st->ebuf == NULL #endif *************** *** 1645,1651 **** } /* ! * Search for tags in the 'tag_fname' tags file. * Information needed to search for the tags is in the 'st' state structure. * The matching tags are returned in 'st'. * Returns OK if successfully processed the file and FAIL on memory allocation --- 1648,1654 ---- } /* ! * Search for tags matching 'st->orgpat.pat' in the 'st->tag_fname' tags file. * Information needed to search for the tags is in the 'st' state structure. * The matching tags are returned in 'st'. * Returns OK if successfully processed the file and FAIL on memory allocation *************** *** 1653,1664 **** */ static int find_tags_in_file( - char_u *tag_fname, findtags_state_T *st, int flags, char_u *buf_ffname) { ! FILE *fp; tagptrs_T tagp; int is_static; // current tag line is static int is_current; // file name matches --- 1656,1666 ---- */ static int find_tags_in_file( findtags_state_T *st, int flags, char_u *buf_ffname) { ! FILE *fp = NULL; tagptrs_T tagp; int is_static; // current tag line is static int is_current; // file name matches *************** *** 1668,1674 **** int i; #ifdef FEAT_MULTI_LANG int help_pri = 0; ! char_u help_lang[3]; // lang of current tags file #endif #ifdef FEAT_TAG_BINS int tag_file_sorted = NUL; // !_TAG_FILE_SORTED value --- 1670,1676 ---- int i; #ifdef FEAT_MULTI_LANG int help_pri = 0; ! char_u help_lang[3] = ""; // lang of current tags file #endif #ifdef FEAT_TAG_BINS int tag_file_sorted = NUL; // !_TAG_FILE_SORTED value *************** *** 1770,1778 **** { // Prefer help tags according to 'helplang'. Put the // two-letter language name in help_lang[]. ! i = (int)STRLEN(tag_fname); ! if (i > 3 && tag_fname[i - 3] == '-') ! STRCPY(help_lang, tag_fname + i - 2); else STRCPY(help_lang, "en"); } --- 1772,1780 ---- { // Prefer help tags according to 'helplang'. Put the // two-letter language name in help_lang[]. ! i = (int)STRLEN(st->tag_fname); ! if (i > 3 && st->tag_fname[i - 3] == '-') ! STRCPY(help_lang, st->tag_fname + i - 2); else STRCPY(help_lang, "en"); } *************** *** 1815,1827 **** } #endif ! if ((fp = mch_fopen((char *)tag_fname, "r")) == NULL) return OK; if (p_verbose >= 5) { verbose_enter(); ! smsg(_("Searching tags file %s"), tag_fname); verbose_leave(); } } --- 1817,1829 ---- } #endif ! if ((fp = mch_fopen((char *)st->tag_fname, "r")) == NULL) return OK; if (p_verbose >= 5) { verbose_enter(); ! smsg(_("Searching tags file %s"), st->tag_fname); verbose_leave(); } } *************** *** 1955,1961 **** --incstack_idx; fclose(fp); // end of this file ... fp = incstack[incstack_idx].fp; ! STRCPY(tag_fname, incstack[incstack_idx].etag_fname); vim_free(incstack[incstack_idx].etag_fname); is_etag = 1; // (only etags can include) continue; // ... continue with parent file --- 1957,1963 ---- --incstack_idx; fclose(fp); // end of this file ... fp = incstack[incstack_idx].fp; ! STRCPY(st->tag_fname, incstack[incstack_idx].etag_fname); vim_free(incstack[incstack_idx].etag_fname); is_etag = 1; // (only etags can include) continue; // ... continue with parent file *************** *** 2024,2030 **** { // Save current "fp" and "tag_fname" in the stack. if ((incstack[incstack_idx].etag_fname = ! vim_strsave(tag_fname)) != NULL) { char_u *fullpath_ebuf; --- 2026,2032 ---- { // Save current "fp" and "tag_fname" in the stack. if ((incstack[incstack_idx].etag_fname = ! vim_strsave(st->tag_fname)) != NULL) { char_u *fullpath_ebuf; *************** *** 2034,2040 **** // Figure out "tag_fname" and "fp" to use for // included file. fullpath_ebuf = expand_tag_fname(st->ebuf, ! tag_fname, FALSE); if (fullpath_ebuf != NULL) { fp = mch_fopen((char *)fullpath_ebuf, "r"); --- 2036,2042 ---- // Figure out "tag_fname" and "fp" to use for // included file. fullpath_ebuf = expand_tag_fname(st->ebuf, ! st->tag_fname, FALSE); if (fullpath_ebuf != NULL) { fp = mch_fopen((char *)fullpath_ebuf, "r"); *************** *** 2042,2048 **** { if (STRLEN(fullpath_ebuf) > LSIZE) semsg(_(e_tag_file_path_truncated_for_str), st->ebuf); ! vim_strncpy(tag_fname, fullpath_ebuf, MAXPATHL); ++incstack_idx; is_etag = 0; // we can include anything --- 2044,2050 ---- { if (STRLEN(fullpath_ebuf) > LSIZE) semsg(_(e_tag_file_path_truncated_for_str), st->ebuf); ! vim_strncpy(st->tag_fname, fullpath_ebuf, MAXPATHL); ++incstack_idx; is_etag = 0; // we can include anything *************** *** 2185,2191 **** --- 2187,2197 ---- vim_free(st->lbuf); st->lbuf = alloc(st->lbuf_size); if (st->lbuf == NULL) + { + if (fp != NULL) + fclose(fp); return FAIL; + } #ifdef FEAT_TAG_BINS if (state == TS_STEP_FORWARD) *************** *** 2424,2430 **** #ifdef FEAT_EMACS_TAGS is_etag, #endif ! tagp.fname, tagp.fname_end, tag_fname, buf_ffname); #ifdef FEAT_EMACS_TAGS is_static = FALSE; --- 2430,2436 ---- #ifdef FEAT_EMACS_TAGS is_etag, #endif ! tagp.fname, tagp.fname_end, st->tag_fname, buf_ffname); #ifdef FEAT_EMACS_TAGS is_static = FALSE; *************** *** 2533,2539 **** } else { ! size_t tag_fname_len = STRLEN(tag_fname); #ifdef FEAT_EMACS_TAGS size_t ebuf_len = 0; #endif --- 2539,2545 ---- } else { ! size_t tag_fname_len = STRLEN(st->tag_fname); #ifdef FEAT_EMACS_TAGS size_t ebuf_len = 0; #endif *************** *** 2561,2567 **** { p = mfp; p[0] = mtt + 1; ! STRCPY(p + 1, tag_fname); #ifdef BACKSLASH_IN_FILENAME // Ignore differences in slashes, avoid adding // both path/file and path\file. --- 2567,2573 ---- { p = mfp; p[0] = mtt + 1; ! STRCPY(p + 1, st->tag_fname); #ifdef BACKSLASH_IN_FILENAME // Ignore differences in slashes, avoid adding // both path/file and path\file. *************** *** 2632,2638 **** if (line_error) { ! semsg(_(e_format_error_in_tags_file_str), tag_fname); #ifdef FEAT_CSCOPE if (!use_cscope) #endif --- 2638,2644 ---- if (line_error) { ! semsg(_(e_format_error_in_tags_file_str), st->tag_fname); #ifdef FEAT_CSCOPE if (!use_cscope) #endif *************** *** 2660,2666 **** tag_file_sorted = NUL; if (sort_error) { ! semsg(_(e_tags_file_not_sorted_str), tag_fname); sort_error = FALSE; } #endif --- 2666,2672 ---- tag_file_sorted = NUL; if (sort_error) { ! semsg(_(e_tags_file_not_sorted_str), st->tag_fname); sort_error = FALSE; } #endif *************** *** 2763,2769 **** char_u *buf_ffname) // name of buffer for priority { findtags_state_T st; - char_u *tag_fname; // name of tag file tagname_T tn; // info for get_tagfname() int first_file; // trying first tag file int retval = FAIL; // return value --- 2769,2774 ---- *************** *** 2811,2830 **** help_save = curbuf->b_help; - /* - * Allocate memory for the buffers that are used - */ - tag_fname = alloc(MAXPATHL + 1); - - // check for out of memory situation - if (tag_fname == NULL) - goto findtag_end; - if (findtags_state_init(&st, pat, mincount) == FAIL) goto findtag_end; #ifdef FEAT_CSCOPE ! STRCPY(tag_fname, "from cscope"); // for error messages #endif /* --- 2816,2826 ---- help_save = curbuf->b_help; if (findtags_state_init(&st, pat, mincount) == FAIL) goto findtag_end; #ifdef FEAT_CSCOPE ! STRCPY(st.tag_fname, "from cscope"); // for error messages #endif /* *************** *** 2918,2927 **** #ifdef FEAT_CSCOPE use_cscope || #endif ! get_tagfname(&tn, first_file, tag_fname) == OK; first_file = FALSE) { ! if (find_tags_in_file(tag_fname, &st, flags, buf_ffname) == FAIL) goto findtag_end; if (st.stop_searching #ifdef FEAT_CSCOPE --- 2914,2923 ---- #ifdef FEAT_CSCOPE use_cscope || #endif ! get_tagfname(&tn, first_file, st.tag_fname) == OK; first_file = FALSE) { ! if (find_tags_in_file(&st, flags, buf_ffname) == FAIL) goto findtag_end; if (st.stop_searching #ifdef FEAT_CSCOPE *************** *** 2963,2971 **** } findtag_end: vim_free(st.lbuf); vim_regfree(st.orgpat.regmatch.regprog); - vim_free(tag_fname); #ifdef FEAT_EMACS_TAGS vim_free(st.ebuf); #endif --- 2959,2967 ---- } findtag_end: + vim_free(st.tag_fname); vim_free(st.lbuf); vim_regfree(st.orgpat.regmatch.regprog); #ifdef FEAT_EMACS_TAGS vim_free(st.ebuf); #endif *** ../vim-8.2.4495/src/version.c 2022-03-02 20:49:43.472155195 +0000 --- src/version.c 2022-03-03 10:43:28.734269456 +0000 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 4496, /**/ -- hundred-and-one symptoms of being an internet addict: 146. You experience ACTUAL physical withdrawal symptoms when away from your 'puter and the net. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///