From df95cd4780e99afee8dcc8be5323221fdc5ac4a5 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 3 Mar 2018 14:43:51 -0800 Subject: [PATCH] Fix #487 dead loop in hierarchical .cquery --- src/project.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/project.cc b/src/project.cc index a3576efb..ce9f13a4 100644 --- a/src/project.cc +++ b/src/project.cc @@ -333,8 +333,12 @@ std::vector LoadFromDirectoryListing(Config* init_opts, auto GetCompilerArgumentForFile = [&config, &folder_args](const std::string& path) { - for (std::string cur = GetDirName(path); - NormalizePath(cur) != config->project_dir; cur = GetDirName(cur)) { + for (std::string cur = GetDirName(path); ; cur = GetDirName(cur)) { + std::string normalized = NormalizePath(cur); + if (normalized.size() <= config->project_dir.size() || + normalized.compare(0, config->project_dir.size(), + config->project_dir) != 0) + break; auto it = folder_args.find(cur); if (it != folder_args.end()) { return it->second;