diff options
Diffstat (limited to 'src/nvim/tag.c')
-rw-r--r-- | src/nvim/tag.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/nvim/tag.c b/src/nvim/tag.c index c09a13edb1..2a980af2a2 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -952,12 +952,12 @@ void do_tags(exarg_T *eap) continue; msg_putchar('\n'); - sprintf((char *)IObuff, "%c%2d %2d %-15s %5ld ", - i == tagstackidx ? '>' : ' ', - i + 1, - tagstack[i].cur_match + 1, - tagstack[i].tagname, - tagstack[i].fmark.mark.lnum); + vim_snprintf((char *)IObuff, IOSIZE, "%c%2d %2d %-15s %5ld ", + i == tagstackidx ? '>' : ' ', + i + 1, + tagstack[i].cur_match + 1, + tagstack[i].tagname, + tagstack[i].fmark.mark.lnum); msg_outtrans(IObuff); msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum ? HL_ATTR(HLF_D) : 0); @@ -2217,6 +2217,16 @@ static bool test_for_static(tagptrs_T *tagp) return FALSE; } +// Returns the length of a matching tag line. +static size_t matching_line_len(const char_u *const lbuf) +{ + const char_u *p = lbuf + 1; + + // does the same thing as parse_match() + p += STRLEN(p) + 1; + return (p - lbuf) + STRLEN(p); +} + /* * Parse a line from a matching tag. Does not change the line itself. * @@ -2300,11 +2310,10 @@ static char_u *tag_full_fname(tagptrs_T *tagp) * * returns OK for success, NOTAGFILE when file not found, FAIL otherwise. */ -static int -jumpto_tag ( - char_u *lbuf, /* line from the tags file for this tag */ - int forceit, /* :ta with ! */ - int keep_help /* keep help flag (FALSE for cscope) */ +static int jumpto_tag( + const char_u *lbuf_arg, // line from the tags file for this tag + int forceit, // :ta with ! + int keep_help // keep help flag (FALSE for cscope) ) { int save_secure; @@ -2312,7 +2321,6 @@ jumpto_tag ( bool save_p_ws; int save_p_scs, save_p_ic; linenr_T save_lnum; - int csave = 0; char_u *str; char_u *pbuf; /* search pattern buffer */ char_u *pbuf_end; @@ -2327,6 +2335,9 @@ jumpto_tag ( char_u *full_fname = NULL; int old_KeyTyped = KeyTyped; /* getting the file may reset it */ const int l_g_do_tagpreview = g_do_tagpreview; + const size_t len = matching_line_len(lbuf_arg) + 1; + char_u *lbuf = xmalloc(len); + memmove(lbuf, lbuf_arg, len); pbuf = xmalloc(LSIZE); @@ -2336,8 +2347,7 @@ jumpto_tag ( goto erret; } - /* truncate the file name, so it can be used as a string */ - csave = *tagp.fname_end; + // truncate the file name, so it can be used as a string *tagp.fname_end = NUL; fname = tagp.fname; @@ -2447,7 +2457,10 @@ jumpto_tag ( else keep_help_flag = curbuf->b_help; } + if (getfile_result == GETFILE_UNUSED) { + // Careful: getfile() may trigger autocommands and call jumpto_tag() + // recursively. getfile_result = getfile(0, fname, NULL, true, (linenr_T)0, forceit); } keep_help_flag = false; @@ -2605,9 +2618,8 @@ jumpto_tag ( } erret: - g_do_tagpreview = 0; /* For next time */ - if (tagp.fname_end != NULL) - *tagp.fname_end = csave; + g_do_tagpreview = 0; // For next time + xfree(lbuf); xfree(pbuf); xfree(tofree_fname); xfree(full_fname); |