Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions cli/signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
// TODO: separate these two defines
#if defined(__linux__) && defined(REG_ERR)
const auto* const uc = reinterpret_cast<const ucontext_t*>(context);
killid = (pid_t) syscall(SYS_gettid);
killid = static_cast<pid_t>(syscall(SYS_gettid));
if (uc) {
type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2;
type = static_cast<int>(uc->uc_mcontext.gregs[REG_ERR]) & 2;
}
#else
(void)context;
Expand Down Expand Up @@ -170,7 +170,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
break;
}
fprintf(output, " (at 0x%lx).\n",
(unsigned long)info->si_addr);
reinterpret_cast<unsigned long>(info->si_addr));
break;
case SIGFPE:
fputs("Internal error: cppcheck received signal ", output);
Expand Down Expand Up @@ -204,7 +204,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
break;
}
fprintf(output, " (at 0x%lx).\n",
(unsigned long)info->si_addr);
reinterpret_cast<unsigned long>(info->si_addr));
break;
case SIGILL:
fputs("Internal error: cppcheck received signal ", output);
Expand Down Expand Up @@ -238,7 +238,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
break;
}
fprintf(output, " (at 0x%lx).%s\n",
(unsigned long)info->si_addr,
reinterpret_cast<unsigned long>(info->si_addr),
(isAddressOnStack)?" Stackoverflow?":"");
break;
case SIGINT:
Expand All @@ -264,7 +264,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
// cppcheck-suppress knownConditionTrueFalse ; FP
(type==-1)? "" :
(type==0) ? "reading " : "writing ",
(unsigned long)info->si_addr,
reinterpret_cast<unsigned long>(info->si_addr),
(isAddressOnStack)?" Stackoverflow?":""
);
break;
Expand Down
8 changes: 4 additions & 4 deletions cli/stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
// 32 vs. 64bit
#define ADDRESSDISPLAYLENGTH ((sizeof(long)==8)?12:8)
void *callstackArray[32]= {nullptr}; // the less resources the better...
const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray));
const int currentdepth = backtrace(callstackArray, static_cast<int>(getArrayLength(callstackArray)));
// set offset to 1 to omit the printing function itself
int offset=start_idx+1; // some entries on top are within our own exception handling code or libc
if (maxdepth<0)
Expand Down Expand Up @@ -86,12 +86,12 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
padLen, 0);
if (realnameString) {
fprintf(output, "%.*s in %s\n",
(int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3,
static_cast<int>(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3,
realnameString);
} else {
fprintf(output, "%.*s in %.*s\n",
(int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3,
(int)(firstBracketAddress-symbolString), symbolString);
static_cast<int>(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3,
static_cast<int>(firstBracketAddress - symbolString), symbolString);
}
}
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) - code matches the documented usage
Expand Down
1 change: 0 additions & 1 deletion cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# TODO: fix and enable these warnings - or move to suppression list below
add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands
add_compile_options_safe(-Wno-unused-exception-parameter)
add_compile_options_safe(-Wno-old-style-cast)
add_compile_options_safe(-Wno-sign-conversion)
add_compile_options_safe(-Wno-shadow-field-in-constructor)
add_compile_options_safe(-Wno-covered-switch-default)
Expand Down
6 changes: 3 additions & 3 deletions gui/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)

QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
int top = static_cast<int>(blockBoundingGeometry(block).translated(contentOffset()).top());
int bottom = top + static_cast<int>(blockBoundingRect(block).height());

while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
Expand All @@ -438,7 +438,7 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)

block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
bottom = top + static_cast<int>(blockBoundingRect(block).height());
++blockNumber;
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/compliancereportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void ComplianceReportDialog::save()
QCryptographicHash hash(QCryptographicHash::Algorithm::Md5);
if (hash.addData(&f)) {
for (auto b: hash.result())
out << QString::number((unsigned char)b,16);
out << QString::number(static_cast<unsigned char>(b),16);
out << " " << fileName << "\n";
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/librarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void LibraryDialog::changeFunction()
return;

function->comments = mUi->comments->toPlainText();
function->noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)mUi->noreturn->currentIndex();
function->noreturn = static_cast<CppcheckLibraryData::Function::TrueFalseUnknown>(mUi->noreturn->currentIndex());
function->useretval = mUi->useretval->isChecked();
function->leakignore = mUi->leakignore->isChecked();

Expand Down
20 changes: 10 additions & 10 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
#else
constexpr Platform::Type defaultPlatform = Platform::Type::Unspecified;
#endif
PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
PlatformData &platform = mPlatforms.get(static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt()));
platform.mActMainWindow->setChecked(true);

mNetworkAccessManager = new QNetworkAccessManager(this);
Expand Down Expand Up @@ -385,7 +385,7 @@ void MainWindow::loadSettings()
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
}

const ReportType reportType = (ReportType)mSettings->value(SETTINGS_REPORT_TYPE, (int)ReportType::normal).toInt();
const ReportType reportType = static_cast<ReportType>(mSettings->value(SETTINGS_REPORT_TYPE, static_cast<int>(ReportType::normal)).toInt());
mUI->mActionReportNormal->setChecked(reportType <= ReportType::normal);
mUI->mActionReportAutosar->setChecked(reportType == ReportType::autosar);
mUI->mActionReportCertC->setChecked(reportType == ReportType::certC);
Expand Down Expand Up @@ -433,7 +433,7 @@ void MainWindow::loadSettings()
mUI->mActionToolBarFilter->setChecked(showFilterToolbar);
mUI->mToolBarFilter->setVisible(showFilterToolbar);

const Standards::Language enforcedLanguage = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
const Standards::Language enforcedLanguage = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());
if (enforcedLanguage == Standards::Language::CPP)
mUI->mActionEnforceCpp->setChecked(true);
else if (enforcedLanguage == Standards::Language::C)
Expand Down Expand Up @@ -483,7 +483,7 @@ void MainWindow::saveSettings() const
mUI->mActionReportMisraCpp2008->isChecked() ? ReportType::misraCpp2008 :
mUI->mActionReportMisraCpp2023->isChecked() ? ReportType::misraCpp2023 :
ReportType::normal;
mSettings->setValue(SETTINGS_REPORT_TYPE, (int)reportType);
mSettings->setValue(SETTINGS_REPORT_TYPE, static_cast<int>(reportType));

// Show * states
mSettings->setValue(SETTINGS_SHOW_STYLE, mUI->mActionShowStyle->isChecked());
Expand Down Expand Up @@ -559,7 +559,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
p.ignorePaths(v);

if (!mProjectFile->getAnalyzeAllVsConfigs()) {
const Platform::Type platform = (Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
const Platform::Type platform = static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
std::vector<std::string> configurations;
const QStringList configs = mProjectFile->getVsConfigurations();
std::transform(configs.cbegin(), configs.cend(), std::back_inserter(configurations), [](const QString& e) {
Expand Down Expand Up @@ -1125,7 +1125,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
settings.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
} else {
for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) {
const auto p = (Platform::Type)i;
const auto p = static_cast<Platform::Type>(i);
if (platform == Platform::toString(p)) {
settings.platform.set(p);
break;
Expand Down Expand Up @@ -1205,10 +1205,10 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
settings.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
settings.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
if (!mProjectFile || settings.platform.type == Platform::Type::Unspecified)
settings.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
settings.platform.set(static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()));
settings.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
settings.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString());
settings.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
settings.enforcedLang = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());

settings.jobs = std::max(settings.jobs, 1u);

Expand Down Expand Up @@ -2133,7 +2133,7 @@ void MainWindow::updateMRUMenuItems()
if (removed)
mSettings->setValue(SETTINGS_MRU_PROJECTS, projects);

const int numRecentProjects = qMin(projects.size(), (int)MaxRecentProjects);
const int numRecentProjects = qMin(projects.size(), static_cast<int>(MaxRecentProjects));
for (int i = 0; i < numRecentProjects; i++) {
const QString filename = QFileInfo(projects[i]).fileName();
const QString text = QString("&%1 %2").arg(i + 1).arg(filename);
Expand Down Expand Up @@ -2172,7 +2172,7 @@ void MainWindow::selectPlatform()
{
auto *action = qobject_cast<QAction *>(sender());
if (action) {
const Platform::Type platform = (Platform::Type) action->data().toInt();
const Platform::Type platform = static_cast<Platform::Type>(action->data().toInt());
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ void ResultsTree::copy()
QString inconclusive = itemdata[INCONCLUSIVE].toBool() ? ",inconclusive" : "";
text += itemdata[FILENAME].toString() + ':' + QString::number(itemdata[LINE].toInt()) + ':' + QString::number(itemdata[COLUMN].toInt())
+ ": "
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)itemdata[SEVERITY].toInt()))) + inconclusive
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity(static_cast<ShowTypes::ShowType>(itemdata[SEVERITY].toInt())))) + inconclusive
+ ": "
+ itemdata[MESSAGE].toString()
+ " ["
Expand Down
2 changes: 1 addition & 1 deletion gui/showtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ShowTypes::ShowType ShowTypes::VariantToShowType(const QVariant &data)
if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) {
return ShowTypes::ShowNone;
}
return (ShowTypes::ShowType)value;
return static_cast<ShowTypes::ShowType>(value);
}

void ShowTypes::load()
Expand Down
2 changes: 1 addition & 1 deletion gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void StatsDialog::pdfExport()
.arg(tr("Information messages"))
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation));

QString fileName = QFileDialog::getSaveFileName((QWidget*)nullptr, tr("Export PDF"), QString(), "*.pdf");
QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Export PDF"), QString(), "*.pdf");
if (QFileInfo(fileName).suffix().isEmpty()) {
fileName.append(".pdf");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::string Check::getMessageId(const ValueFlow::Value &value, const char id[])
if (value.condition != nullptr)
return id + std::string("Cond");
if (value.safe)
return std::string("safe") + (char)std::toupper(id[0]) + (id + 1);
return std::string("safe") + static_cast<char>(std::toupper(id[0])) + (id + 1);
return id;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void CheckIO::invalidScanf()
format = false;
}

else if (std::isalpha((unsigned char)formatstr[i]) || formatstr[i] == '[') {
else if (std::isalpha(static_cast<unsigned char>(formatstr[i])) || formatstr[i] == '[') {
if (formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) // #3490 - field width limits are only necessary for string input
invalidScanfError(tok);
format = false;
Expand Down Expand Up @@ -645,7 +645,7 @@ void CheckIO::checkFormatString(const Token * const tok,
std::string width;
int parameterPosition = 0;
bool hasParameterPosition = false;
while (i != formatString.cend() && *i != '[' && !std::isalpha((unsigned char)*i)) {
while (i != formatString.cend() && *i != '[' && !std::isalpha(static_cast<unsigned char>(*i))) {
if (*i == '*') {
skip = true;
if (scan)
Expand Down
10 changes: 5 additions & 5 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
percent = false;

bool _continue = false;
while (!std::isalpha((unsigned char)*i)) {
while (!std::isalpha(static_cast<unsigned char>(*i))) {
if (*i == '*') {
if (scan)
_continue = true;
Expand Down Expand Up @@ -474,11 +474,11 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var

std::string id = "nullPointer";
if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
errmsg = "If memory allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
errmsg = "If memory allocation fails, then there is a " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1));
id += "OutOfMemory";
}
else if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
errmsg = "If resource allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
errmsg = "If resource allocation fails, then there is a " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1));
id += "OutOfResources";
}

Expand Down Expand Up @@ -553,11 +553,11 @@ void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow:

std::string id = "nullPointerArithmetic";
if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
errmsg = "If memory allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
errmsg = "If memory allocation fails: " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1));
id += "OutOfMemory";
}
else if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
errmsg = "If resource allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
errmsg = "If resource allocation fails: " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1));
id += "OutOfResources";
}

Expand Down
6 changes: 3 additions & 3 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void CheckType::checkIntegerOverflow()
continue;

// max value according to platform settings.
const MathLib::bigint maxvalue = (((MathLib::biguint)1) << (bits - 1)) - 1;
const MathLib::bigint maxvalue = (static_cast<MathLib::biguint>(1) << (bits - 1)) - 1;

// is there a overflow result value
bool isOverflow = true;
Expand All @@ -213,7 +213,7 @@ void CheckType::checkIntegerOverflow()
continue;

// For left shift, it's common practice to shift into the sign bit
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits))
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (static_cast<MathLib::biguint>(1) << bits))
continue;

integerOverflowError(tok, *value, isOverflow);
Expand Down Expand Up @@ -507,7 +507,7 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v
bits = mSettings->platform.long_long_bit;
else
continue;
if (bits < MathLib::bigint_bits && f.floatValue >= (((MathLib::biguint)1) << bits))
if (bits < MathLib::bigint_bits && f.floatValue >= (static_cast<MathLib::biguint>(1) << bits))
floatToIntegerOverflowError(tok, f);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ static std::vector<std::string> splitString(const std::string &line)
pos2 = line.find('\"', pos1+1);
else if (line[pos1] == '\'') {
pos2 = line.find('\'', pos1+1);
if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
if (pos2 < static_cast<int>(line.size()) - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
pos2 = line.find('\'', pos2 + 3);
} else {
pos2 = pos1;
while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum((unsigned char)line[pos2])))
while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum(static_cast<unsigned char>(line[pos2]))))
++pos2;
if (pos2 > pos1 && pos2 < line.size() && line[pos2] == '<' && std::isalpha(line[pos1])) {
int tlevel = 1;
Expand Down Expand Up @@ -1267,7 +1267,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
return addtoken(tokenList, getSpelling());
}
if (nodeType == UnaryOperator) {
int index = (int)mExtTokens.size() - 1;
int index = static_cast<int>(mExtTokens.size()) - 1;
while (index > 0 && mExtTokens[index][0] != '\'')
--index;
Token *unop = addtoken(tokenList, unquote(mExtTokens[index]));
Expand Down
Loading