From c128495aace477883dbb1db83e8c6c213be65738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Feb 2026 10:52:51 +0100 Subject: [PATCH 1/4] Fix #14532 (Release 2.20: Update Cppcheck Premium checkers mapping) --- lib/checkersidmapping.cpp | 11 +++++------ lib/checkexceptionsafety.cpp | 2 +- lib/checkother.cpp | 2 +- lib/settings.cpp | 8 ++++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/checkersidmapping.cpp b/lib/checkersidmapping.cpp index 5b0e6705c4c..64f1af1f206 100644 --- a/lib/checkersidmapping.cpp +++ b/lib/checkersidmapping.cpp @@ -1,6 +1,6 @@ /* * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2025 Cppcheck team. + * Copyright (C) 2007-2026 Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,7 +41,6 @@ std::vector checkers::idMappingAutosar{ {"m5-0-17", "comparePointers"}, {"m5-0-18", "comparePointers"}, {"a5-1-4", "returnDanglingLifetime"}, - {"a5-2-2", "cstyleCast"}, {"a5-2-5", "arrayIndexOutOfBounds,arrayIndexOutOfBoundsCond,pointerOutOfBounds,pointerOutOfBoundsCond,negativeIndex,arrayIndexThenCheck,bufferAccessOutOfBounds,objectIndex,argumentSize"}, {"m5-3-4", "sizeofFunctionCall"}, {"a5-3-2", "nullPointer,nullPointerRedundantCheck,nullPointerArithmetic,nullPointerArithmeticRedundantCheck,nullPointerDefaultArg"}, @@ -99,13 +98,13 @@ std::vector checkers::idMappingCertCpp{ {"CTR51", "eraseDereference"}, {"CTR54", "comparePointers"}, {"CTR55", "containerOutOfBounds"}, - {"DCL57", "deallocThrow,exceptThrowInDestructor"}, + {"DCL57", "exceptDeallocThrow,exceptThrowInDestructor"}, {"DCL60", "ctuOneDefinitionRuleViolation"}, {"ERR57", "memleak"}, {"EXP52", "sizeofCalculation"}, {"EXP53", "uninitvar,uninitdata,uninitStructMember"}, {"EXP54", "uninitvar,danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime"}, - {"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime"}, + {"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime,useAfterFree"}, {"EXP63", "accessMoved"}, {"FIO50", "IOWithoutPositioning"}, {"MEM50", "deallocuse"}, @@ -124,7 +123,7 @@ std::vector checkers::idMappingMisraC{ {"1.1", "syntaxError"}, {"1.3", "error"}, {"2.1", "duplicateBreak,unreachableCode"}, - {"2.2", "constStatement,redundantCondition,redundantAssignment,redundantAssignInSwitch,unreadVariable"}, + {"2.2", "constStatement,redundantCondition,redundantAssignment,redundantAssignInSwitch,unreadVariable,unusedFunction"}, {"2.6", "unusedLabel"}, {"2.8", "unusedVariable"}, {"5.3", "shadowVariable"}, @@ -168,7 +167,7 @@ std::vector checkers::idMappingMisraCpp2008{ {"5-0-16", "pointerOutOfBounds"}, {"5-0-17", "comparePointers"}, {"5-0-18", "comparePointers"}, - {"5-2-4", "cstyleCast"}, + {"5-2-4", "cstyleCast,dangerousTypeCast"}, {"5-3-4", "sizeofFunctionCall"}, {"5-8-1", "shiftTooManyBits"}, {"6-6-5", "missingReturn"}, diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 36cec717d90..61f1ad8c784 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -95,7 +95,7 @@ void CheckExceptionSafety::destructorsError(const Token * const tok, const std:: void CheckExceptionSafety::deallocThrow() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("exceptDeallocThrow")) return; logChecker("CheckExceptionSafety::deallocThrow"); // warning diff --git a/lib/checkother.cpp b/lib/checkother.cpp index de6e295e04a..2402ac070c8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -415,7 +415,7 @@ void CheckOther::warningDangerousTypeCast() // Only valid on C++ code if (!mTokenizer->isCPP()) return; - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("cstyleCast")) + if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("dangerousTypeCast")) return; logChecker("CheckOther::warningDangerousTypeCast"); // warning,c++ diff --git a/lib/settings.cpp b/lib/settings.cpp index 8e4b8d2a6d4..57d598316c8 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -354,7 +354,6 @@ static const std::set autosarCheckers{ "bufferAccessOutOfBounds", "comparePointers", "constParameter", - "cstyleCast", "ctuOneDefinitionRuleViolation", "doubleFree", "duplInheritedMember", @@ -466,10 +465,10 @@ static const std::set certCppCheckers{ "danglingReference", "danglingTempReference", "danglingTemporaryLifetime", - "deallocThrow", "deallocuse", "doubleFree", "eraseDereference", + "exceptDeallocThrow", "exceptThrowInDestructor", "initializerList", "invalidContainer", @@ -483,6 +482,7 @@ static const std::set certCppCheckers{ "uninitStructMember", "uninitdata", "uninitvar", + "useAfterFree", "virtualCallInConstructor", "virtualDestructor" }; @@ -524,6 +524,7 @@ static const std::set misrac2012Checkers{ "unknownEvaluationOrder", "unreachableCode", "unreadVariable", + "unusedFunction", "unusedLabel", "unusedVariable", "useClosedFile", @@ -567,6 +568,7 @@ static const std::set misrac2023Checkers{ "unknownEvaluationOrder", "unreachableCode", "unreadVariable", + "unusedFunction", "unusedLabel", "unusedVariable", "useClosedFile", @@ -610,6 +612,7 @@ static const std::set misrac2025Checkers{ "unknownEvaluationOrder", "unreachableCode", "unreadVariable", + "unusedFunction", "unusedLabel", "unusedVariable", "useClosedFile", @@ -623,6 +626,7 @@ static const std::set misracpp2008Checkers{ "constVariable", "cstyleCast", "ctuOneDefinitionRuleViolation", + "dangerousTypeCast", "danglingLifetime", "duplInheritedMember", "duplicateBreak", From 52b9648d08746e2e31dbf472297ef2b3364bdea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Feb 2026 11:43:55 +0100 Subject: [PATCH 2/4] update --- lib/checkclass.cpp | 18 ++++++++++-------- lib/settings.cpp | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f56c799b247..aeca3950f6b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2748,15 +2748,17 @@ namespace { // avoid one-definition-rule violation void CheckClass::initializerListOrder() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("initializerList")) - return; + if (!mSettings->isPremiumEnabled("initializerList")) { + if (!mSettings->severity.isEnabled(Severity::style)) + return; - // This check is not inconclusive. However it only determines if the initialization - // order is incorrect. It does not determine if being out of order causes - // a real error. Out of order is not necessarily an error but you can never - // have an error if the list is in order so this enforces defensive programming. - if (!mSettings->certainty.isEnabled(Certainty::inconclusive)) - return; + // This check is not inconclusive. However it only determines if the initialization + // order is incorrect. It does not determine if being out of order causes + // a real error. Out of order is not necessarily an error but you can never + // have an error if the list is in order so this enforces defensive programming. + if (!mSettings->certainty.isEnabled(Certainty::inconclusive)) + return; + } logChecker("CheckClass::initializerListOrder"); // style,inconclusive diff --git a/lib/settings.cpp b/lib/settings.cpp index 57d598316c8..4c1a1273e5d 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -458,6 +458,14 @@ static const std::set certCCheckers{ static const std::set certCppCheckers{ "IOWithoutPositioning", "accessMoved", + "argumentSize", + "arrayIndexOutOfBounds", + "arrayIndexOutOfBoundsCond", + "arrayIndexThenCheck", + "autoVariables", + "autovarInvalidDeallocation", + "bitwiseOnBoolean", + "bufferAccessOutOfBounds", "comparePointers", "containerOutOfBounds", "ctuOneDefinitionRuleViolation", @@ -465,26 +473,51 @@ static const std::set certCppCheckers{ "danglingReference", "danglingTempReference", "danglingTemporaryLifetime", + "deallocret", "deallocuse", "doubleFree", "eraseDereference", "exceptDeallocThrow", "exceptThrowInDestructor", + "floatConversionOverflow", "initializerList", + "integerOverflow", "invalidContainer", + "invalidFunctionArg", + "invalidLengthModifierError", + "invalidLifetime", + "invalidScanfFormatWidth", + "invalidscanf", + "leakReturnValNotUsed", + "leakUnsafeArgAlloc", "memleak", + "memleakOnRealloc", "mismatchAllocDealloc", "missingReturn", + "negativeIndex", "nullPointer", + "nullPointerArithmetic", + "nullPointerArithmeticRedundantCheck", + "nullPointerDefaultArg", + "nullPointerRedundantCheck", + "objectIndex", "operatorEqToSelf", + "pointerOutOfBounds", + "pointerOutOfBoundsCond", + "preprocessorErrorDirective", + "resourceLeak", "returnDanglingLifetime", "sizeofCalculation", + "stringLiteralWrite", "uninitStructMember", "uninitdata", "uninitvar", "useAfterFree", + "useClosedFile", "virtualCallInConstructor", - "virtualDestructor" + "virtualDestructor", + "wrongPrintfScanfArgNum", + "wrongPrintfScanfParameterPositionError" }; static const std::set misrac2012Checkers{ From d062d48c8fcca87a9765f8a8c7e4347e46b5f448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Feb 2026 15:35:38 +0100 Subject: [PATCH 3/4] cleanup --- lib/checkersidmapping.cpp | 2 +- lib/settings.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/checkersidmapping.cpp b/lib/checkersidmapping.cpp index 64f1af1f206..a87759ca0ad 100644 --- a/lib/checkersidmapping.cpp +++ b/lib/checkersidmapping.cpp @@ -24,7 +24,7 @@ std::vector checkers::idMappingAutosar{ {"m0-1-1", "unreachableCode,duplicateBreak"}, {"m0-1-2", "unsignedLessThanZero"}, {"m0-1-3", "unusedVariable,unusedStructMember"}, - {"a0-1-1", "unreadVariable,unusedValue,redundantAssignment"}, + {"a0-1-1", "unreadVariable,redundantAssignment"}, {"m0-1-9", "redundantAssignment,redundantInitialization"}, {"m0-1-10", "unusedFunction"}, {"m0-2-1", "overlappingWriteUnion,overlappingWriteFunction"}, diff --git a/lib/settings.cpp b/lib/settings.cpp index 4c1a1273e5d..1abaffc77f1 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -395,7 +395,6 @@ static const std::set autosarCheckers{ "unsignedLessThanZero", "unusedFunction", "unusedStructMember", - "unusedValue", "unusedVariable", "useInitializationList", "variableScope", From 88ef80543657cb97e26faee7f7fe44800c7d1934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Feb 2026 15:38:18 +0100 Subject: [PATCH 4/4] deallocuse --- lib/checkersidmapping.cpp | 2 +- lib/settings.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/checkersidmapping.cpp b/lib/checkersidmapping.cpp index a87759ca0ad..e9636843853 100644 --- a/lib/checkersidmapping.cpp +++ b/lib/checkersidmapping.cpp @@ -104,7 +104,7 @@ std::vector checkers::idMappingCertCpp{ {"EXP52", "sizeofCalculation"}, {"EXP53", "uninitvar,uninitdata,uninitStructMember"}, {"EXP54", "uninitvar,danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime"}, - {"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime,useAfterFree"}, + {"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime,deallocuse,deallocret"}, {"EXP63", "accessMoved"}, {"FIO50", "IOWithoutPositioning"}, {"MEM50", "deallocuse"}, diff --git a/lib/settings.cpp b/lib/settings.cpp index 1abaffc77f1..305af5a143c 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -511,7 +511,6 @@ static const std::set certCppCheckers{ "uninitStructMember", "uninitdata", "uninitvar", - "useAfterFree", "useClosedFile", "virtualCallInConstructor", "virtualDestructor",