Fix ClangImport crash on Windows paths (#4246)
* Fix crash on Windows paths * Fix test * Enable fix * Cut trailing ':'
This commit is contained in:
parent
b170a9c61e
commit
22aeeb1788
|
@ -497,17 +497,21 @@ void clangimport::AstNode::dumpAst(int num, int indent) const
|
||||||
void clangimport::AstNode::setLocations(TokenList *tokenList, int file, int line, int col)
|
void clangimport::AstNode::setLocations(TokenList *tokenList, int file, int line, int col)
|
||||||
{
|
{
|
||||||
for (const std::string &ext: mExtTokens) {
|
for (const std::string &ext: mExtTokens) {
|
||||||
if (ext.compare(0,5,"<col:") == 0)
|
if (ext.compare(0, 5, "<col:") == 0)
|
||||||
col = std::atoi(ext.substr(5).c_str());
|
col = std::atoi(ext.substr(5).c_str());
|
||||||
else if (ext.compare(0,6,"<line:") == 0) {
|
else if (ext.compare(0, 6, "<line:") == 0) {
|
||||||
line = std::atoi(ext.substr(6).c_str());
|
line = std::atoi(ext.substr(6).c_str());
|
||||||
if (ext.find(", col:") != std::string::npos)
|
if (ext.find(", col:") != std::string::npos)
|
||||||
col = std::atoi(ext.c_str() + ext.find(", col:") + 6);
|
col = std::atoi(ext.c_str() + ext.find(", col:") + 6);
|
||||||
} else if (ext[0] == '<' && ext.find(":") != std::string::npos) {
|
} else if (ext[0] == '<') {
|
||||||
std::string::size_type sep1 = ext.find(":");
|
const std::string::size_type colon = ext.find(':');
|
||||||
std::string::size_type sep2 = ext.find(":", sep1+1);
|
if (colon != std::string::npos) {
|
||||||
file = tokenList->appendFileIfNew(ext.substr(1, sep1 - 1));
|
const bool windowsPath = colon == 2 && ext.size() > 4 && ext[3] == '\\';
|
||||||
line = MathLib::toLongNumber(ext.substr(sep1+1, sep2-sep1));
|
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 - 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mFile = file;
|
mFile = file;
|
||||||
|
|
|
@ -584,7 +584,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void cxxRecordDecl1() {
|
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));
|
ASSERT_EQUALS("class Foo ;", parse(clang));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue