Skip to content

Commit ff22de1

Browse files
authored
Fix #13831 (do not execute misra.py in cppcheck premium when --premium=misra-c-.. options are used) (#7506)
1 parent e9042ae commit ff22de1

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

cli/cmdlineparser.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11681168
return Result::Fail;
11691169
}
11701170
mSettings.premiumArgs += "--" + p;
1171-
if (p == "misra-c-2012" || p == "misra-c-2023")
1172-
mSettings.addons.emplace("misra");
11731171
if (startsWith(p, "autosar") || startsWith(p, "cert") || startsWith(p, "misra")) {
11741172
// All checkers related to the coding standard should be enabled. The coding standards
11751173
// do not all undefined behavior or portability issues.

gui/mainwindow.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,7 @@ QString MainWindow::loadAddon(Settings &settings, const QString &filesDir, const
10101010
if (!misraFile.isEmpty()) {
10111011
QString arg;
10121012
picojson::array arr;
1013-
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
1014-
arg = "--misra-pdf=" + misraFile;
1015-
else
1016-
arg = "--rule-texts=" + misraFile;
1013+
arg = "--rule-texts=" + misraFile;
10171014
arr.emplace_back(arg.toStdString());
10181015
obj["args"] = picojson::value(arr);
10191016
}
@@ -1039,6 +1036,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
10391036
Settings::terminate(true);
10401037

10411038
settings.exename = QCoreApplication::applicationFilePath().toStdString();
1039+
settings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
10421040

10431041
// default to --check-level=normal for GUI for now
10441042
settings.setCheckLevel(Settings::CheckLevel::normal);
@@ -1157,6 +1155,8 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
11571155
settings.checkUnknownFunctionReturn.insert(s.toStdString());
11581156

11591157
for (const QString& addon : mProjectFile->getAddons()) {
1158+
if (isCppcheckPremium() && addon == "misra")
1159+
continue;
11601160
const QString addonError = loadAddon(settings, filesDir, pythonCmd, addon);
11611161
if (!addonError.isEmpty()) {
11621162
QMessageBox::critical(this, tr("Error"), tr("%1\n\nAnalysis is aborted.").arg(addonError));
@@ -1172,7 +1172,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
11721172
premiumArgs += " --cert-c-int-precision=" + QString::number(mProjectFile->getCertIntPrecision());
11731173
for (const QString& c: mProjectFile->getCodingStandards())
11741174
premiumArgs += " --" + c;
1175-
if (!premiumArgs.contains("misra") && mProjectFile->getAddons().contains("misra"))
1175+
if (!premiumArgs.contains("--misra-c-") && mProjectFile->getAddons().contains("misra"))
11761176
premiumArgs += " --misra-c-2012";
11771177
settings.premiumArgs = premiumArgs.mid(1).toStdString();
11781178
settings.setMisraRuleTexts(CheckThread::executeCommand);

lib/errorlogger.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
10161016
}
10171017
break;
10181018
case ReportType::misraC:
1019-
if (errId.rfind("misra-c20", 0) == 0)
1019+
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0)
10201020
guideline = errId.substr(errId.rfind('-') + 1);
10211021
break;
10221022
case ReportType::misraCpp2008:

test/cli/premium_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,19 @@ def _get_hash(s:str):
114114
assert hash1 != hash2
115115

116116

117+
def test_misra_py(tmpdir):
118+
# 13831 - do not execute misra.py when --premium=misra-c-2012 is used
119+
test_file = os.path.join(tmpdir, 'test.c')
120+
with open(test_file, 'wt') as f:
121+
f.write('void foo();\n')
122+
123+
exe = __copy_cppcheck_premium(tmpdir)
124+
125+
# ensure that misra.py is not available:
126+
_, stdout, _ = cppcheck(['--enable=style', '--addon=misra', test_file], cppcheck_exe=exe)
127+
assert 'Did not find addon misra.py' in stdout
128+
129+
# Execute misra
130+
_, stdout, _ = cppcheck(['--enable=style', '--premium=misra-c-2012', test_file], cppcheck_exe=exe)
131+
assert 'misra.py' not in stdout # Did not find misra.py
132+
assert 'Checking' in stdout

0 commit comments

Comments
 (0)