Skip to content

Commit 2e67588

Browse files
committed
Fix segfault when file path cannot be resolved
1 parent a10d3a3 commit 2e67588

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bindgen/visitor/TreeVisitor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,15 @@ bool TreeVisitor::VisitVarDecl(clang::VarDecl *varDecl) {
175175
std::shared_ptr<Location> TreeVisitor::getLocation(clang::Decl *decl) {
176176
clang::SourceManager &sm = astContext->getSourceManager();
177177
std::string filename = std::string(sm.getFilename(decl->getLocation()));
178-
std::string path = realpath(filename.c_str(), nullptr);
178+
char *p = realpath(filename.c_str(), nullptr);
179+
std::string path;
180+
if (p) {
181+
path = p;
182+
delete[] p;
183+
} else {
184+
// TODO: check when it happens
185+
path = "";
186+
}
179187

180188
unsigned lineNumber = sm.getSpellingLineNumber(decl->getLocation());
181189
return std::make_shared<Location>(path, lineNumber);

0 commit comments

Comments
 (0)