Skip to contentSkip to conversation

pre-proc: do some path normalization

PATCH New Luc Van Oostenryck 1 participant 1 message Mar 1, 2021 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pre-proc: do some path normalization

An header file like 'header.h':

	#pragma once
	#include "./header.h"

doesn't work because:
1) both filenames are different, so it will be be included anyway
2) after that it will be included again under the name "././header.h" and so on until it eventually fails with ENAMETOOLONG.

Prevent this by stripping leading "./"s in the paths. This is not good enough for testing file equivalence by is enough to avoid the loop.

---
 pre-process.c | 6 ++++++
 1 file changed, 6 insertions(+)
pre-process.c +6 -0
index 7a1478f6a0f1..3fb250828fa6 100644
@@ -884,6 +884,12 @@ static void set_stream_include_path(struct stream *stream)
 			memcpy(m, stream->name, len);
 			m[len] = 0;
 			path = m;
+			/* normalize this path */
+			while (path[0] == '.' && path[1] == '/') {
+				path += 2;
+				while (path[0] == '/')
+					path++;
+			}
 		}
 		stream->path = path;
 	}
Signature · 1 line
2.30.0