Fixed crash when "-rp=" or "--relative-paths=" is given - print Error.
This commit is contained in:
parent
9857f8d0a2
commit
9f054fbb3c
|
@ -254,13 +254,18 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->_relativePaths = true;
|
||||
else if (strncmp(argv[i], "-rp=", 4) == 0 || strncmp(argv[i], "--relative-paths=", 17) == 0) {
|
||||
_settings->_relativePaths = true;
|
||||
std::string paths = argv[i]+(argv[i][3]=='='?4:17);
|
||||
std::string::size_type pos;
|
||||
do {
|
||||
pos = paths.find(';');
|
||||
_settings->_basePaths.push_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
||||
paths.erase(0, pos+1);
|
||||
} while (pos != std::string::npos);
|
||||
if (argv[i][argv[i][3]=='='?4:17] != 0) {
|
||||
std::string paths = argv[i]+(argv[i][3]=='='?4:17);
|
||||
std::string::size_type pos;
|
||||
do {
|
||||
pos = paths.find(';');
|
||||
_settings->_basePaths.push_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
||||
paths.erase(0, pos+1);
|
||||
} while (pos != std::string::npos);
|
||||
} else {
|
||||
PrintMessage("cppcheck: No paths specified for the '" + std::string(argv[i]) + "' option.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Write results in results.xml
|
||||
|
|
|
@ -157,7 +157,7 @@ std::string Path::getFilenameExtensionInLowerCase(const std::string &path)
|
|||
std::string Path::getRelativePath(const std::string& absolutePath, const std::vector<std::string>& basePaths)
|
||||
{
|
||||
for (std::vector<std::string>::const_iterator i = basePaths.begin(); i != basePaths.end(); ++i) {
|
||||
if (absolutePath == *i) // Seems to be a file
|
||||
if (absolutePath == *i || i->empty()) // Seems to be a file, or path is empty
|
||||
continue;
|
||||
|
||||
bool endsWithSep = (*i)[i->length()-1] == '/';
|
||||
|
|
|
@ -79,6 +79,7 @@ private:
|
|||
|
||||
void getRelative() {
|
||||
std::vector<std::string> basePaths;
|
||||
basePaths.push_back(""); // Don't crash with empty paths
|
||||
basePaths.push_back("C:/foo");
|
||||
basePaths.push_back("C:/bar/");
|
||||
basePaths.push_back("C:/test.cpp");
|
||||
|
|
Loading…
Reference in New Issue