Fix MakeGen crashing when entering invalid filepaths in dependency

This commit is contained in:
Thraix
2020-03-01 21:01:27 +01:00
parent 4b48413941
commit f2afec473f
5 changed files with 21 additions and 11 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# This Makefile was generated using MakeGen v1.3.0 made by Tim Håkansson
# This Makefile was generated using MakeGen v1.3.2 made by Tim Håkansson
# and is licensed under MIT. Full source of the project can be found at
# https://github.com/Thraix/MakeGen
CC=@g++
+1 -1
View File
@@ -19,5 +19,5 @@
<srcdir>src/</srcdir>
</configuration>
<target>Release</target>
<version>v1.3.1</version>
<version>v1.3.2</version>
</makegen>
+1 -1
View File
@@ -12,7 +12,7 @@
// Release, should be backwards compatible with any minor version
#define MAKEGEN_VERSION_RELEASE 3
// Minor changes, generally bug fixes
#define MAKEGEN_VERSION_MINOR 1
#define MAKEGEN_VERSION_MINOR 2
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
+4 -2
View File
@@ -333,6 +333,8 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath)
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs)
{
std::string realPath = FileUtils::GetRealPath(filepath);
if(realPath == "")
return {};
auto it = loadedConfigs.find(realPath);
if(it != loadedConfigs.end())
{
@@ -471,7 +473,7 @@ ConfigFile ConfigFile::Gen()
configuration.AddXMLObject(XMLObject("srcdir", {}, srcdir));
configuration.AddXMLObject(XMLObject("outputdir", {}, outputdir));
configuration.AddXMLObject(XMLObject("hfilename", {}, hFile));
configuration.AddXMLObject(XMLObject("outputtype", {},
configuration.AddXMLObject(XMLObject("outputtype", {},
executable ? "executable" : (shared ? "sharedlibrary" : "staticlibrary")));
configuration.AddXMLObject(XMLObject("generatehfile", {}, generateHFile ? "true" : "false"));
@@ -489,7 +491,7 @@ ConfigFile ConfigFile::Gen()
configuration.AddXMLObject({"dependency",{},*it});
makegen.AddXMLObject(configuration);
return ConfigFile{makegen, FileUtils::GetRealPath("./")};
return ConfigFile{makegen, FileUtils::GetRealPath(".")};
}
void ConfigFile::Save() const
+14 -6
View File
@@ -59,14 +59,22 @@ struct FileUtils
static std::string GetRealPath(const std::string& filename)
{
#if defined(__linux__)
char* path = realpath(filename.c_str(), NULL);
std::string sPath = path;
sPath+="/";
free(path);
return sPath;
if(access(filename.c_str(), F_OK ) != -1)
{
char* path = realpath(filename.c_str(), NULL);
std::string sPath = path;
sPath+="/";
free(path);
return sPath;
}
else
{
LOG_ERROR("Directory doesn't exist: ", filename);
return "";
}
#endif
LOG_ERROR("GetRealPath not supported");
return filename;
return "";
}
static std::string GetRelativePath(std::string from, std::string to)