shithub: rgbds

Download patch

ref: e50bcaa2725a3538433455fed617f198fed7b47d
parent: 86a28e8201d1ab0a00544228c44fbe7fef19d81d
author: ISSOtm <[email protected]>
date: Mon Jan 13 11:21:13 EST 2020

Enforce trailing slash in include paths
Fixes rednex#456

--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -316,7 +316,11 @@
 	if (NextIncPath == MAXINCPATHS)
 		fatalerror("Too many include directories passed from command line");
 
-	if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, "%s",
+	// Find last occurrence of slash; is it at the end of the string?
+	char const *lastSlash = strrchr(s, '/');
+	char const *pattern = lastSlash && *(lastSlash + 1) == 0 ? "%s" : "%s/";
+
+	if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, pattern,
 		     s) >= _MAX_PATH)
 		fatalerror("Include path too long '%s'", s);
 }