Partial fix #11892 (Safety: status message when checkers are skipped) (#5368)

This commit is contained in:
Daniel Marjamäki 2023-08-25 13:38:27 +02:00 committed by GitHub
parent 6017c254dd
commit 74ad7243ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 22 deletions

View File

@ -191,13 +191,7 @@ void ComplianceReportDialog::save()
"--project-version=" + projectVersion,
"--output-file=" + outFile};
if (std.startsWith("misra-c-")) {
args << "--misra-c"
<< "--compliant=misra-c2012-1.1"
<< "--compliant=misra-c2012-1.2";
} else {
args << ("--" + std);
}
if (files)
args << "--files=" + tempFiles.fileName();

View File

@ -47,7 +47,7 @@
<widget class="QComboBox" name="mCodingStandard">
<item>
<property name="text">
<string>Misra C 2023</string>
<string>Misra C</string>
</property>
</item>
<item>

View File

@ -1020,11 +1020,10 @@ Settings MainWindow::getCppcheckSettings()
premiumArgs += " --bughunting";
if (mProjectFile->getCertIntPrecision() > 0)
premiumArgs += " --cert-c-int-precision=" + QString::number(mProjectFile->getCertIntPrecision());
if (mProjectFile->getAddons().contains("misra"))
premiumArgs += " --misra-c-2012";
for (const QString& c: mProjectFile->getCodingStandards()) {
for (const QString& c: mProjectFile->getCodingStandards())
premiumArgs += " --" + c;
}
if (!premiumArgs.contains("misra") && mProjectFile->getAddons().contains("misra"))
premiumArgs += " --misra-c-2012";
result.premiumArgs = premiumArgs.mid(1).toStdString();
}
}
@ -1495,7 +1494,16 @@ void MainWindow::save()
void MainWindow::complianceReport()
{
if (isCppcheckPremium() && mProjectFile && mProjectFile->getAddons().contains("misra")) {
if (!mUI->mResults->isSuccess()) {
QMessageBox m(QMessageBox::Critical,
"Cppcheck",
tr("Cannot generate a compliance report right now, an analysis must finish successfully. Try to reanalyze the code and ensure there are no critical errors."),
QMessageBox::Ok,
this);
m.exec();
return;
}
QTemporaryFile tempResults;
tempResults.open();
tempResults.close();
@ -1504,7 +1512,6 @@ void MainWindow::complianceReport()
ComplianceReportDialog dlg(mProjectFile, tempResults.fileName());
dlg.exec();
}
}
void MainWindow::resultsAdded()
@ -1574,6 +1581,7 @@ void MainWindow::aboutToShowViewMenu()
void MainWindow::stopAnalysis()
{
mThread->stop();
mUI->mResults->stopAnalysis();
mUI->mResults->disableProgressbar();
const QString &lastResults = getLastResults();
if (!lastResults.isEmpty()) {

View File

@ -90,6 +90,7 @@ void ResultsView::initialize(QSettings *settings, ApplicationList *list, ThreadH
{
mUI->mProgress->setMinimum(0);
mUI->mProgress->setVisible(false);
mUI->mLabelCriticalErrors->setVisible(false);
CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
mUI->mCode->setStyle(theStyle);
@ -120,6 +121,10 @@ void ResultsView::clear(bool results)
mUI->mProgress->setMaximum(PROGRESS_MAX);
mUI->mProgress->setValue(0);
mUI->mProgress->setFormat("%p%");
mUI->mLabelCriticalErrors->setVisible(false);
mSuccess = false;
}
void ResultsView::clear(const QString &filename)
@ -145,6 +150,8 @@ void ResultsView::progress(int value, const QString& description)
void ResultsView::error(const ErrorItem &item)
{
handleCriticalError(item);
if (mUI->mTree->addErrorItem(item)) {
emit gotResults();
mStatistics->addItem(item.tool(), ShowTypes::SeverityToShowType(item.severity));
@ -277,6 +284,7 @@ QString ResultsView::getCheckDirectory()
void ResultsView::checkingStarted(int count)
{
mSuccess = true;
mUI->mProgress->setVisible(true);
mUI->mProgress->setMaximum(PROGRESS_MAX);
mUI->mProgress->setValue(0);
@ -349,6 +357,8 @@ void ResultsView::disableProgressbar()
void ResultsView::readErrorsXml(const QString &filename)
{
mSuccess = false; // Don't know if results come from an aborted analysis
const int version = XmlReport::determineVersion(filename);
if (version == 0) {
QMessageBox msgBox;
@ -377,6 +387,7 @@ void ResultsView::readErrorsXml(const QString &filename)
}
for (const ErrorItem& item : errors) {
handleCriticalError(item);
mUI->mTree->addErrorItem(item);
}
@ -506,3 +517,38 @@ void ResultsView::on_mListLog_customContextMenuRequested(const QPoint &pos)
contextMenu.exec(globalPos);
}
void ResultsView::stopAnalysis()
{
mSuccess = false;
mUI->mLabelCriticalErrors->setText(tr("Analysis was stopped"));
mUI->mLabelCriticalErrors->setVisible(true);
}
void ResultsView::handleCriticalError(const ErrorItem &item)
{
const QSet<QString> criticalErrors{
"cppcheckError",
"cppcheckLimit",
"internalAstError",
"instantiationError",
"internalError",
"preprocessorErrorDirective",
"syntaxError",
"unknownMacro"
};
if (criticalErrors.contains(item.errorId)) {
QString msg = tr("There was a critical error with id '%1'").arg(item.errorId);
if (!item.file0.isEmpty())
msg += ", " + tr("when checking %1").arg(item.file0);
msg += ". " + tr("Analysis was aborted.");
mUI->mLabelCriticalErrors->setText(msg);
mUI->mLabelCriticalErrors->setVisible(true);
mSuccess = false;
}
}
bool ResultsView::isSuccess() const {
return mSuccess;
}

View File

@ -176,6 +176,17 @@ public:
*/
void translate();
/**
* @brief This function should be called when analysis is stopped
*/
void stopAnalysis();
/**
* @brief Are there successful results?
* @return true if analysis finished without critical errors etc
*/
bool isSuccess() const;
void disableProgressbar();
/**
@ -340,7 +351,14 @@ public slots:
*/
void logCopyComplete();
protected:
private:
/**
* If provided ErrorItem is a critical error then display warning message
* in the resultsview
*/
void handleCriticalError(const ErrorItem& item);
/**
* @brief Should we show a "No errors found dialog" every time no errors were found?
*/
@ -350,6 +368,11 @@ protected:
CheckStatistics *mStatistics;
/**
* Set to true when checking finish successfully. Set to false whenever analysis starts.
*/
bool mSuccess = false;
private slots:
/**
* @brief Custom context menu for Analysis Log

View File

@ -51,6 +51,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="mLabelCriticalErrors">
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
<property name="text">
<string>Critical errors</string>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="mVerticalSplitter">
<property name="orientation">