Skip to content

Commit 65183fc

Browse files
authored
Merge branch 'cppcheck-opensource:main' into main
2 parents ff2b767 + 186a7a9 commit 65183fc

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

cli/cmdlineparser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11591159
if (!parseNumberArg(argv[i], 31, tmp, true))
11601160
return Result::Fail;
11611161
}
1162-
mSettings.premiumArgs += "--" + p;
1162+
if (p.find(' ') != std::string::npos)
1163+
mSettings.premiumArgs += "\"--" + p + "\"";
1164+
else
1165+
mSettings.premiumArgs += "--" + p;
11631166
if (isCodingStandard) {
11641167
// All checkers related to the coding standard should be enabled. The coding standards
11651168
// do not all undefined behavior or portability issues.

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,9 @@ namespace {
27202720
return false;
27212721
}
27222722

2723+
if (!tok->tokAt(-1))
2724+
return false;
2725+
27232726
// skip other using with this name
27242727
if (tok1->strAt(-1) == "using") {
27252728
// fixme: this is wrong

test/testcmdlineparser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class TestCmdlineParser : public TestFixture {
262262
TEST_CASE(premiumOptionsMetrics);
263263
TEST_CASE(premiumOptionsCertCIntPrecision);
264264
TEST_CASE(premiumOptionsLicenseFile);
265+
TEST_CASE(premiumOptionsLicenseFilePathWithSpace);
265266
TEST_CASE(premiumOptionsInvalid1);
266267
TEST_CASE(premiumOptionsInvalid2);
267268
TEST_CASE(premiumSafety);
@@ -1642,6 +1643,14 @@ class TestCmdlineParser : public TestFixture {
16421643
ASSERT_EQUALS("--license-file=file.lic", settings->premiumArgs);
16431644
}
16441645

1646+
void premiumOptionsLicenseFilePathWithSpace() {
1647+
REDIRECT;
1648+
asPremium();
1649+
const char * const argv[] = {"cppcheck", "--premium-license-file=license folder/file.lic", "file.c"};
1650+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
1651+
ASSERT_EQUALS("\"--license-file=license folder/file.lic\"", settings->premiumArgs);
1652+
}
1653+
16451654
void premiumOptionsInvalid1() {
16461655
REDIRECT;
16471656
asPremium();

test/testsimplifyusing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TestSimplifyUsing : public TestFixture {
7777
TEST_CASE(simplifyUsing37);
7878
TEST_CASE(simplifyUsing38);
7979
TEST_CASE(simplifyUsing39);
80+
TEST_CASE(simplifyUsing40);
8081

8182
TEST_CASE(simplifyUsing8970);
8283
TEST_CASE(simplifyUsing8971);
@@ -940,6 +941,13 @@ class TestSimplifyUsing : public TestFixture {
940941
ASSERT_EQUALS("", errout_str());
941942
}
942943

944+
void simplifyUsing40() {
945+
const char code[] = "uint8_t f();\n" // #14876
946+
"using ::std::uint8_t;";
947+
const char expected[] = "uint8_t f ( ) ;";
948+
ASSERT_EQUALS(expected, tok(code));
949+
}
950+
943951
void simplifyUsing8970() {
944952
const char code[] = "using V = std::vector<int>;\n"
945953
"struct A {\n"

0 commit comments

Comments
 (0)