Fix ClangImport crash on Windows paths (#4246)

* Fix crash on Windows paths

* Fix test

* Enable fix

* Cut trailing ':'
This commit is contained in:
chrchr-github 2022-07-02 17:43:52 +02:00 committed by GitHub
parent b170a9c61e
commit 22aeeb1788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -503,11 +503,15 @@ void clangimport::AstNode::setLocations(TokenList *tokenList, int file, int line
line = std::atoi(ext.substr(6).c_str());
if (ext.find(", col:") != std::string::npos)
col = std::atoi(ext.c_str() + ext.find(", col:") + 6);
} else if (ext[0] == '<' && ext.find(":") != std::string::npos) {
std::string::size_type sep1 = ext.find(":");
std::string::size_type sep2 = ext.find(":", sep1+1);
} else if (ext[0] == '<') {
const std::string::size_type colon = ext.find(':');
if (colon != std::string::npos) {
const bool windowsPath = colon == 2 && ext.size() > 4 && ext[3] == '\\';
std::string::size_type sep1 = windowsPath ? ext.find(':', 4) : colon;
std::string::size_type sep2 = ext.find(':', sep1 + 1);
file = tokenList->appendFileIfNew(ext.substr(1, sep1 - 1));
line = MathLib::toLongNumber(ext.substr(sep1+1, sep2-sep1));
line = MathLib::toLongNumber(ext.substr(sep1 + 1, sep2 - sep1 - 1));
}
}
}
mFile = file;

View File

@ -584,7 +584,10 @@ private:
}
void cxxRecordDecl1() {
const char clang[] = "`-CXXRecordDecl 0x34cc5f8 <1.cpp:2:1, col:7> col:7 class Foo";
const char* clang = "`-CXXRecordDecl 0x34cc5f8 <1.cpp:2:1, col:7> col:7 class Foo";
ASSERT_EQUALS("class Foo ;", parse(clang));
clang = "`-CXXRecordDecl 0x34cc5f8 <C:\\Foo\\Bar Baz\\1.cpp:2:1, col:7> col:7 class Foo";
ASSERT_EQUALS("class Foo ;", parse(clang));
}