comparison src/tag.c @ 10611:6bff81438f27 v8.0.0195

patch 8.0.0195: fail to jump to static tag in current file commit https://github.com/vim/vim/commit/a9d23c20879d0dcb289a4db54b3c7df060f87c3c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 16 20:53:34 2017 +0100 patch 8.0.0195: fail to jump to static tag in current file Problem: Jumping to a tag that is a static item in the current file fails. (Kazunobu Kuriyama) Solution: Make sure the first byte of the tag key is not NUL. (Suggested by James McCoy, closes #1387)
author Christian Brabandt <cb@256bit.org>
date Mon, 16 Jan 2017 21:00:04 +0100
parents 1b09db809d3f
children 5ca7e3ec1263
comparison
equal deleted inserted replaced
10610:02610b4928a2 10611:6bff81438f27
42 */ 42 */
43 #define MT_ST_CUR 0 /* static match in current file */ 43 #define MT_ST_CUR 0 /* static match in current file */
44 #define MT_GL_CUR 1 /* global match in current file */ 44 #define MT_GL_CUR 1 /* global match in current file */
45 #define MT_GL_OTH 2 /* global match in other file */ 45 #define MT_GL_OTH 2 /* global match in other file */
46 #define MT_ST_OTH 3 /* static match in other file */ 46 #define MT_ST_OTH 3 /* static match in other file */
47 #define MT_IC_ST_CUR 4 /* icase static match in current file */
48 #define MT_IC_GL_CUR 5 /* icase global match in current file */
49 #define MT_IC_GL_OTH 6 /* icase global match in other file */
50 #define MT_IC_ST_OTH 7 /* icase static match in other file */
51 #define MT_IC_OFF 4 /* add for icase match */ 47 #define MT_IC_OFF 4 /* add for icase match */
52 #define MT_RE_OFF 8 /* add for regexp match */ 48 #define MT_RE_OFF 8 /* add for regexp match */
53 #define MT_MASK 7 /* mask for printing priority */ 49 #define MT_MASK 7 /* mask for printing priority */
54 #define MT_COUNT 16 50 #define MT_COUNT 16
55 51
2315 temp_end++; 2311 temp_end++;
2316 2312
2317 if (tagp.command + 2 < temp_end) 2313 if (tagp.command + 2 < temp_end)
2318 { 2314 {
2319 len = (int)(temp_end - tagp.command - 2); 2315 len = (int)(temp_end - tagp.command - 2);
2320 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1); 2316 mfp = (char_u *)alloc(len + 2);
2321 if (mfp != NULL) 2317 if (mfp != NULL)
2322 vim_strncpy(mfp, tagp.command + 2, len); 2318 vim_strncpy(mfp, tagp.command + 2, len);
2323 } 2319 }
2324 else 2320 else
2325 mfp = NULL; 2321 mfp = NULL;
2349 * Use 0x01 to separate fields (Can't use NUL, because the 2345 * Use 0x01 to separate fields (Can't use NUL, because the
2350 * hash key is terminated by NUL). 2346 * hash key is terminated by NUL).
2351 * Emacs tag: <mtt><tag_fname><0x01><ebuf><0x01><lbuf><NUL> 2347 * Emacs tag: <mtt><tag_fname><0x01><ebuf><0x01><lbuf><NUL>
2352 * other tag: <mtt><tag_fname><0x01><0x01><lbuf><NUL> 2348 * other tag: <mtt><tag_fname><0x01><0x01><lbuf><NUL>
2353 * without Emacs tags: <mtt><tag_fname><0x01><lbuf><NUL> 2349 * without Emacs tags: <mtt><tag_fname><0x01><lbuf><NUL>
2350 * Here <mtt> is the "mtt" value plus 1 to avoid NUL.
2354 */ 2351 */
2355 len = (int)tag_fname_len + (int)STRLEN(lbuf) + 3; 2352 len = (int)tag_fname_len + (int)STRLEN(lbuf) + 3;
2356 #ifdef FEAT_EMACS_TAGS 2353 #ifdef FEAT_EMACS_TAGS
2357 if (is_etag) 2354 if (is_etag)
2358 { 2355 {
2364 #endif 2361 #endif
2365 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1); 2362 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1);
2366 if (mfp != NULL) 2363 if (mfp != NULL)
2367 { 2364 {
2368 p = mfp; 2365 p = mfp;
2369 p[0] = mtt; 2366 p[0] = mtt + 1;
2370 STRCPY(p + 1, tag_fname); 2367 STRCPY(p + 1, tag_fname);
2371 #ifdef BACKSLASH_IN_FILENAME 2368 #ifdef BACKSLASH_IN_FILENAME
2372 /* Ignore differences in slashes, avoid adding 2369 /* Ignore differences in slashes, avoid adding
2373 * both path/file and path\file. */ 2370 * both path/file and path\file. */
2374 slash_adjust(p + 1); 2371 slash_adjust(p + 1);
2546 mfp = hi->hi_key; 2543 mfp = hi->hi_key;
2547 if (matches == NULL) 2544 if (matches == NULL)
2548 vim_free(mfp); 2545 vim_free(mfp);
2549 else 2546 else
2550 { 2547 {
2551 /* now change the TAG_SEP back to NUL */ 2548 if (!name_only)
2552 for (p = mfp; *p != NUL; ++p) 2549 {
2553 if (*p == TAG_SEP) 2550 /* Change mtt back to zero-based. */
2554 *p = NUL; 2551 *mfp = *mfp - 1;
2552
2553 /* change the TAG_SEP back to NUL */
2554 for (p = mfp + 1; *p != NUL; ++p)
2555 if (*p == TAG_SEP)
2556 *p = NUL;
2557 }
2555 matches[match_count++] = (char_u *)mfp; 2558 matches[match_count++] = (char_u *)mfp;
2556 } 2559 }
2557 todo--; 2560 todo--;
2558 } 2561 }
2559 } 2562 }