From 430ed0f0582d225be74f91b83c847cc4609acd08 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 7 Mar 2015 14:08:19 +0000 Subject: [PATCH] fix crash on Windows if SplitFileName is called with empty filename --- Common/StringUtils.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 827c1dc29f..8378af230c 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -91,17 +91,20 @@ std::string FixRelativePath(const std::string &reference, const std::string &in) std::vector<std::string> SplitFileName(const std::string &fileName) { - // returns [path, baseName, extension] - int idot = (int)fileName.find_last_of('.'); - int islash = (int)fileName.find_last_of("/\\"); - if(idot == (int)std::string::npos) idot = -1; - if(islash == (int)std::string::npos) islash = -1; - 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 - if(idot > 0) - s[2] = fileName.substr(idot); - 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()); + // JFR DO NOT CHANGE TO std::vector<std::string> s(3), it segfaults while destructor si called + std::vector<std::string> s; s.resize(3); + if(fileName.size()){ + // returns [path, baseName, extension] + int idot = (int)fileName.find_last_of('.'); + int islash = (int)fileName.find_last_of("/\\"); + if(idot == (int)std::string::npos) idot = -1; + if(islash == (int)std::string::npos) islash = -1; + if(idot > 0) + s[2] = fileName.substr(idot); + 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; } -- GitLab