Skip to content
Snippets Groups Projects
Commit 430ed0f0 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix crash on Windows if SplitFileName is called with empty filename

parent 81a612f9
No related branches found
No related tags found
No related merge requests found
...@@ -91,17 +91,20 @@ std::string FixRelativePath(const std::string &reference, const std::string &in) ...@@ -91,17 +91,20 @@ std::string FixRelativePath(const std::string &reference, const std::string &in)
std::vector<std::string> SplitFileName(const std::string &fileName) std::vector<std::string> SplitFileName(const std::string &fileName)
{ {
// returns [path, baseName, extension] // JFR DO NOT CHANGE TO std::vector<std::string> s(3), it segfaults while destructor si called
int idot = (int)fileName.find_last_of('.'); std::vector<std::string> s; s.resize(3);
int islash = (int)fileName.find_last_of("/\\"); if(fileName.size()){
if(idot == (int)std::string::npos) idot = -1; // returns [path, baseName, extension]
if(islash == (int)std::string::npos) islash = -1; int idot = (int)fileName.find_last_of('.');
std::vector<std::string> s; s.resize(3); // JFR DO NOT CHANGE TO std::vector<std::string> s(3), it segfaults while destructor si called int islash = (int)fileName.find_last_of("/\\");
if(idot > 0) if(idot == (int)std::string::npos) idot = -1;
s[2] = fileName.substr(idot); if(islash == (int)std::string::npos) islash = -1;
if(islash > 0) if(idot > 0)
s[0] = fileName.substr(0, islash + 1); s[2] = fileName.substr(idot);
s[1] = fileName.substr(s[0].size(), fileName.size() - s[0].size() - s[2].size()); if(islash > 0)
s[0] = fileName.substr(0, islash + 1);
s[1] = fileName.substr(s[0].size(), fileName.size() - s[0].size() - s[2].size());
}
return s; return s;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment