From 3dc64b0b0a7d4e14ccea6b9d1d11bf871c47a7e0 Mon Sep 17 00:00:00 2001 From: Thibault DUPONCHELLE Date: Wed, 20 Mar 2019 09:26:47 +0100 Subject: Add test case for bug #1 + proposed fix. Fixes: https://gitlab.freedesktop.org/xorg/util/makedepend/issues/1 --- include.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'include.c') diff --git a/include.c b/include.c index 159dfc7..697e9de 100644 --- a/include.c +++ b/include.c @@ -241,8 +241,38 @@ inc_path(const char *file, const char *include, int type) for (; ip->i_file; ip++) { if ((strcmp(ip->i_incstring, include) == 0) && !(ip->i_flags & INCLUDED_SYM)) { - inclistnext = ip + 1; - return ip; + /* + * Same filename but same file ? + */ + char r_include[PATHMAX+1]; + char r_saved_path[PATHMAX+1]; + char* ptr; + ptr = realpath(include, r_include); + ptr = realpath(ip->i_file, r_saved_path); + if (!strcmp(r_include, r_saved_path)) { + inclistnext = ip + 1; + return ip; + } + + /* + * Check if we have a header in the same dir + */ + for (p=file+strlen(file); p>file; p--) + if (*p == '/') + break; + if (p == file) { + strcpy(path, include); + } else { + strncpy(path, file, (p-file) + 1); + path[ (p-file) + 1 ] = '\0'; + strcpy(path + (p-file) + 1, include); + } + remove_dotdot(path); + ptr = realpath(path, r_include); + if (!strcmp(r_include, r_saved_path)) { + inclistnext = ip + 1; + return ip; + } } } -- cgit v1.2.3