summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault DUPONCHELLE <thibault.duponchelle@gmail.com>2019-03-20 09:26:47 +0100
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-04-10 09:48:37 -0700
commit3dc64b0b0a7d4e14ccea6b9d1d11bf871c47a7e0 (patch)
treef10a95192d492478917e18938142d4fad36b713b
parent54559e73e27e532535dea2a60e615f99c694343f (diff)
Add test case for bug #1 + proposed fix.
Fixes: https://gitlab.freedesktop.org/xorg/util/makedepend/issues/1
-rw-r--r--Makefile.am4
-rw-r--r--def.h1
-rw-r--r--include.c34
-rwxr-xr-xtests/1/makedep.sh39
-rw-r--r--tests/1/one.cpp1
-rw-r--r--tests/1/two.cpp1
6 files changed, 78 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 00b695e..1eb2eb8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,3 +71,7 @@ TESTS_ENVIRONMENT += test_srcdir="$(TEST_SRCDIR_PATH)/tests"
# Test for https://bugs.freedesktop.org/show_bug.cgi?id=28045
TESTS += tests/28045/makedep.sh
EXTRA_DIST += tests/28045/makedep.sh tests/28045/foo.cpp
+
+# Test
+TESTS += tests/1/makedep.sh
+EXTRA_DIST += tests/1/makedep.sh tests/1/one.cpp tests/1/two.cpp
diff --git a/def.h b/def.h
index 17ce537..479adcc 100644
--- a/def.h
+++ b/def.h
@@ -42,6 +42,7 @@ in this Software without prior written authorization from The Open Group.
#define MAXFILES 2048
#define MAXINCFILES 128 /* "-include" files */
#define MAXDIRS 512 /* -I flags */
+#define PATHMAX 4096 /* realpath */
#define SYMTABINC 10 /* must be > 1 for define() to work right */
#define TRUE 1
#define FALSE 0
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;
+ }
}
}
diff --git a/tests/1/makedep.sh b/tests/1/makedep.sh
new file mode 100755
index 0000000..f24e2ff
--- /dev/null
+++ b/tests/1/makedep.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# Test case for bug https://gitlab.freedesktop.org/xorg/util/makedepend/issues/1
+
+set -e
+
+if [ "x$test_srcdir" = "x" ]; then
+ test_srcdir=..
+fi
+
+if [ "x$test_builddir" = "x" ]; then
+ test_builddir=..
+fi
+
+if [ "x$MAKEDEPEND" = "x" ]; then
+ MAKEDEPEND=makedepend
+fi
+
+mkdir -p ${test_builddir}/1
+cd ${test_builddir}/1
+
+pwd
+
+# Create test conditions:
+# - directory named "one" containing file one.cpp which includes def.h in the same directory
+# - directory named "two" containing file two.cpp which includes def.h in the same directory
+mkdir -p one two
+
+# 2 headers with the same name but in different directories
+touch one/def.h two/def.h
+cp ${test_srcdir}/1/one.cpp one/
+cp ${test_srcdir}/1/two.cpp two/
+
+# two/two.cpp depends on two/def.h (not the one seen during exploration in previous directory)
+$MAKEDEPEND -f- -I. one/one.cpp two/two.cpp | grep "two/two.o: one/def.h" && false
+
+
+# Clean up
+rm -rf one two
diff --git a/tests/1/one.cpp b/tests/1/one.cpp
new file mode 100644
index 0000000..bb9f760
--- /dev/null
+++ b/tests/1/one.cpp
@@ -0,0 +1 @@
+#include "def.h"
diff --git a/tests/1/two.cpp b/tests/1/two.cpp
new file mode 100644
index 0000000..bb9f760
--- /dev/null
+++ b/tests/1/two.cpp
@@ -0,0 +1 @@
+#include "def.h"