Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:

- name: Self check (unusedFunction / no test / no gui)
run: |
supprs="--suppress=unusedFunction:lib/errorlogger.h:193 --suppress=unusedFunction:lib/importproject.cpp:1508 --suppress=unusedFunction:lib/importproject.cpp:1532"
supprs="--suppress=unusedFunction:lib/errorlogger.h:193 --suppress=unusedFunction:lib/importproject.cpp:1518 --suppress=unusedFunction:lib/importproject.cpp:1542"
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr $supprs
env:
DISABLE_VALUEFLOW: 1
Expand Down
14 changes: 12 additions & 2 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,27 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command,
pos++;
if (pos >= command.size())
break;
bool wholeArgQuoted = false;
if (command[pos] == '"') {
wholeArgQuoted = true;
pos++;
Comment thread
ludviggunne marked this conversation as resolved.
if (pos >= command.size())
break;
}
if (command[pos] != '/' && command[pos] != '-')
continue;
Comment thread
danmar marked this conversation as resolved.
pos++;
if (pos >= command.size())
break;
const char F = command[pos++];
if (std::strchr("DUI", F)) {
while (pos < command.size() && command[pos] == ' ')
while (pos < command.size() && command[pos] == ' ') {
++pos;
wholeArgQuoted = false;
Comment thread
danmar marked this conversation as resolved.
Outdated
}
}
std::string fval = readUntil(command, &pos, " =");
const char *readUntilChars = wholeArgQuoted ? " =\"" : " =";
Comment thread
danmar marked this conversation as resolved.
Outdated
std::string fval = readUntil(command, &pos, readUntilChars);
if (F=='D') {
std::string defval = readUntil(command, &pos, " ");
defs += fval;
Expand Down
21 changes: 21 additions & 0 deletions test/testimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TestImportProject : public TestFixture {
TEST_CASE(importCompileCommands12); // #13040: "directory" is parent directory, relative include paths
TEST_CASE(importCompileCommands13); // #13333: duplicate file entries
TEST_CASE(importCompileCommands14); // #14156
TEST_CASE(importCompileCommands15); // #14306
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
TEST_CASE(importCompileCommandsDirectoryMissing); // 'directory' field missing
Expand Down Expand Up @@ -389,6 +390,26 @@ class TestImportProject : public TestFixture {
ASSERT_EQUALS("TFS_LINUX_MODULE_NAME=\"tfs_linux\"", fs.defines);
}

void importCompileCommands15() const { // #14306
REDIRECT;
constexpr char json[] =
R"([
{
"directory": "C:\\Users\\abcd\\efg\\hijk",
"command": "gcc \"-Ipath\\123\" \"-c\" test.c",
"file": "test.c",
"output": "test.obj"
}
])";
std::istringstream istr(json);
TestImporter importer;
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
ASSERT_EQUALS(1, importer.fileSettings.size());
const FileSettings &fs = importer.fileSettings.front();
ASSERT_EQUALS(1, fs.includePaths.size());
ASSERT_EQUALS("C:/Users/abcd/efg/hijk/path/123/", fs.includePaths.front());
}

void importCompileCommandsArgumentsSection() const {
REDIRECT;
constexpr char json[] = "[ { \"directory\": \"/tmp/\","
Expand Down
Loading