Fixed #8637 (GUI: Supression filename should accept relative paths)

This commit is contained in:
Daniel Marjamäki 2019-04-18 09:52:29 +02:00
parent 0c7d4eb91f
commit b2e3af5869
2 changed files with 22 additions and 5 deletions

View File

@ -28,7 +28,10 @@
#include <QFile>
#include <QInputDialog>
#include "mainwindow.h"
#include "cppcheck.h"
#include "path.h"
#include "applicationlist.h"
#include "aboutdialog.h"
#include "common.h"
@ -56,6 +59,19 @@ static QString getDataDir(const QSettings *settings)
return dataDir.isEmpty() ? appPath : dataDir;
}
static QList<Suppressions::Suppression> getCheckSuppressions(const ProjectFile &project)
{
QList<Suppressions::Suppression> ret;
const std::string projectFilePath = Path::getPathFromFilename(project.getFilename().toStdString());
foreach (Suppressions::Suppression suppression, project.getSuppressions()) {
if (!suppression.fileName.empty() && suppression.fileName[0]!='*' && !Path::isAbsolute(suppression.fileName))
suppression.fileName = Path::simplifyPath(projectFilePath) + suppression.fileName;
ret.append(suppression);
}
return ret;
}
MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mSettings(settings),
mApplications(new ApplicationList(this)),
@ -442,7 +458,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString());
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
mThread->setClangIncludePaths(clangHeaders.split(";"));
mThread->setSuppressions(mProjectFile->getSuppressions());
mThread->setSuppressions(getCheckSuppressions(*mProjectFile));
}
mThread->setProject(p);
mThread->check(checkSettings);
@ -841,8 +857,8 @@ Settings MainWindow::getCppcheckSettings()
tryLoadLibrary(&result.library, filename);
}
const QList<Suppressions::Suppression> &suppressions = mProjectFile->getSuppressions();
foreach (const Suppressions::Suppression &suppression, suppressions) {
foreach (const Suppressions::Suppression &suppression, getCheckSuppressions(*mProjectFile)) {
result.nomsg.addSuppression(suppression);
}

View File

@ -2,7 +2,7 @@
#include "ui_newsuppressiondialog.h"
#include "cppcheck.h"
#include "errorlogger.h"
#include "suppressions.h"
NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
QDialog(parent),
@ -41,7 +41,8 @@ Suppressions::Suppression NewSuppressionDialog::getSuppression() const
if (ret.errorId.empty())
ret.errorId = "*";
ret.fileName = mUI->mTextFileName->text().toStdString();
ret.lineNumber = mUI->mTextLineNumber->text().toInt();
if (!mUI->mTextLineNumber->text().isEmpty())
ret.lineNumber = mUI->mTextLineNumber->text().toInt();
ret.symbolName = mUI->mTextSymbolName->text().toStdString();
return ret;
}