Re: failure when searching by complete filename with -P and --color=always options
Shigio YAMAGUCHI <[email protected]>
| Newsgroups | gmane.comp.gnu.global.bugs |
|---|---|
| Message-ID | <CADJmJYrsduqPxE+a3pvbik3n++87sPE0T7ajQG7W5aMu1z+-Mw@mail.gmail.com> |
Hi, > $ cd hi/what ... > $ global -P --color=always hi/foo.cpp > foo.cpp > ^^^^^^^ (this is wrong!!) It will be fixed by the attached patch, I believe. Could you please try it? Thank you for the report! Regards, Shigio 2015-12-30 6:47 GMT+09:00 William Xu <[email protected]>: > Hi, > > I find a nasty bug that when searching a filename with its complete > path, together with -P and --color=always options, the returned file > path is incorrect, missing a "../" at the front. Below is steps for > reproducing. > > version: global (GNU GLOBAL) 6.5.2 > OS: Mac OS 10.11.2 > > ---------------------------------8<------------------------------------- > $ tree . > . > |-- GPATH > |-- GRTAGS > |-- GTAGS > `-- hi > |-- bar.cpp > |-- foo.cpp > `-- what > > 2 directories, 5 files > > $ cd hi/what > $ global -P --color=always foo.cpp > ../foo.cpp > > $ global -P --color=always hi/foo.cpp > foo.cpp > ^^^^^^^ (this is wrong!!) > > $ global -P hi/foo.cpp > ../foo.cpp > ---------------------------------8<------------------------------------- > > -- > William > > Never have so many understood so little about so much. > -- James Burke > > > _______________________________________________ > Bug-global mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/bug-global > -- Shigio YAMAGUCHI <[email protected]> PGP fingerprint: D1CB 0B89 B346 4AB6 5663 C4B6 3CA5 BBB3 57BE DDA3 _______________________________________________ Bug-global mailing list [email protected] https://lists.gnu.org/mailman/listinfo/bug-global
abs2rel.patch
(application/octet-stream, 1.8 KB)
Index: libutil/abs2rel.c
===================================================================
RCS file: /sources/global/global/libutil/abs2rel.c,v
retrieving revision 1.20
diff -c -r1.20 abs2rel.c
*** libutil/abs2rel.c 22 Jun 2015 06:42:50 -0000 1.20
--- libutil/abs2rel.c 30 Dec 2015 09:19:39 -0000
***************
*** 359,365 ****
char *
abs2rel(const char *path, const char *base, char *result, int size)
{
! const char *pp, *bp, *branch;
/*
* endp points the last position which is safe in the result buffer.
*/
--- 359,365 ----
char *
abs2rel(const char *path, const char *base, char *result, int size)
{
! const char *pp, *bp, *branch, *branch_b;
/*
* endp points the last position which is safe in the result buffer.
*/
***************
*** 384,389 ****
--- 384,390 ----
* seek to branched point.
*/
branch = path;
+ branch_b = base;
for (pp = path, bp = base; *pp && *bp; pp++, bp++) {
#ifdef COLOR_PATH
/* skip escape sequence */
***************
*** 401,408 ****
#endif
if (PATHCHAR(*pp) != PATHCHAR(*bp))
break;
! if (*pp == '/')
branch = pp;
}
if ((*pp == 0 || (*pp == '/' && *(pp + 1) == 0)) &&
(*bp == 0 || (*bp == '/' && *(bp + 1) == 0))) {
--- 402,411 ----
#endif
if (PATHCHAR(*pp) != PATHCHAR(*bp))
break;
! if (*pp == '/') {
branch = pp;
+ branch_b = bp;
+ }
}
if ((*pp == 0 || (*pp == '/' && *(pp + 1) == 0)) &&
(*bp == 0 || (*bp == '/' && *(bp + 1) == 0))) {
***************
*** 435,441 ****
* up to root.
*/
rp = result;
! for (bp = base + (branch - path); *bp; bp++)
if (*bp == '/' && *(bp + 1) != 0) {
if (rp + 3 > endp)
goto erange;
--- 438,444 ----
* up to root.
*/
rp = result;
! for (bp = branch_b; *bp; bp++)
if (*bp == '/' && *(bp + 1) != 0) {
if (rp + 3 > endp)
goto erange;