Skip to content

Commit 9bb6ee8

Browse files
authored
Fix #14532 (Release 2.20: Update Cppcheck Premium checkers mapping) (#8260)
1 parent da9399d commit 9bb6ee8

5 files changed

Lines changed: 57 additions & 21 deletions

File tree

lib/checkclass.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,15 +2750,17 @@ namespace { // avoid one-definition-rule violation
27502750

27512751
void CheckClass::initializerListOrder()
27522752
{
2753-
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("initializerList"))
2754-
return;
2753+
if (!mSettings->isPremiumEnabled("initializerList")) {
2754+
if (!mSettings->severity.isEnabled(Severity::style))
2755+
return;
27552756

2756-
// This check is not inconclusive. However it only determines if the initialization
2757-
// order is incorrect. It does not determine if being out of order causes
2758-
// a real error. Out of order is not necessarily an error but you can never
2759-
// have an error if the list is in order so this enforces defensive programming.
2760-
if (!mSettings->certainty.isEnabled(Certainty::inconclusive))
2761-
return;
2757+
// This check is not inconclusive. However it only determines if the initialization
2758+
// order is incorrect. It does not determine if being out of order causes
2759+
// a real error. Out of order is not necessarily an error but you can never
2760+
// have an error if the list is in order so this enforces defensive programming.
2761+
if (!mSettings->certainty.isEnabled(Certainty::inconclusive))
2762+
return;
2763+
}
27622764

27632765
logChecker("CheckClass::initializerListOrder"); // style,inconclusive
27642766

lib/checkersidmapping.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Cppcheck - A tool for static C/C++ code analysis
3-
* Copyright (C) 2007-2025 Cppcheck team.
3+
* Copyright (C) 2007-2026 Cppcheck team.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ std::vector<checkers::IdMapping> checkers::idMappingAutosar{
2424
{"m0-1-1", "unreachableCode,duplicateBreak"},
2525
{"m0-1-2", "unsignedLessThanZero"},
2626
{"m0-1-3", "unusedVariable,unusedStructMember"},
27-
{"a0-1-1", "unreadVariable,unusedValue,redundantAssignment"},
27+
{"a0-1-1", "unreadVariable,redundantAssignment"},
2828
{"m0-1-9", "redundantAssignment,redundantInitialization"},
2929
{"m0-1-10", "unusedFunction"},
3030
{"m0-2-1", "overlappingWriteUnion,overlappingWriteFunction"},
@@ -41,7 +41,6 @@ std::vector<checkers::IdMapping> checkers::idMappingAutosar{
4141
{"m5-0-17", "comparePointers"},
4242
{"m5-0-18", "comparePointers"},
4343
{"a5-1-4", "returnDanglingLifetime"},
44-
{"a5-2-2", "cstyleCast"},
4544
{"a5-2-5", "arrayIndexOutOfBounds,arrayIndexOutOfBoundsCond,pointerOutOfBounds,pointerOutOfBoundsCond,negativeIndex,arrayIndexThenCheck,bufferAccessOutOfBounds,objectIndex,argumentSize"},
4645
{"m5-3-4", "sizeofFunctionCall"},
4746
{"a5-3-2", "nullPointer,nullPointerRedundantCheck,nullPointerArithmetic,nullPointerArithmeticRedundantCheck,nullPointerDefaultArg"},
@@ -99,13 +98,13 @@ std::vector<checkers::IdMapping> checkers::idMappingCertCpp{
9998
{"CTR51", "eraseDereference"},
10099
{"CTR54", "comparePointers"},
101100
{"CTR55", "containerOutOfBounds"},
102-
{"DCL57", "deallocThrow,exceptThrowInDestructor"},
101+
{"DCL57", "exceptDeallocThrow,exceptThrowInDestructor"},
103102
{"DCL60", "ctuOneDefinitionRuleViolation"},
104103
{"ERR57", "memleak"},
105104
{"EXP52", "sizeofCalculation"},
106105
{"EXP53", "uninitvar,uninitdata,uninitStructMember"},
107106
{"EXP54", "uninitvar,danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime"},
108-
{"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime"},
107+
{"EXP61", "danglingLifetime,danglingReference,danglingTemporaryLifetime,danglingTempReference,returnDanglingLifetime,deallocuse,deallocret"},
109108
{"EXP63", "accessMoved"},
110109
{"FIO50", "IOWithoutPositioning"},
111110
{"MEM50", "deallocuse"},
@@ -124,7 +123,7 @@ std::vector<checkers::IdMapping> checkers::idMappingMisraC{
124123
{"1.1", "syntaxError"},
125124
{"1.3", "error"},
126125
{"2.1", "duplicateBreak,unreachableCode"},
127-
{"2.2", "constStatement,redundantCondition,redundantAssignment,redundantAssignInSwitch,unreadVariable"},
126+
{"2.2", "constStatement,redundantCondition,redundantAssignment,redundantAssignInSwitch,unreadVariable,unusedFunction"},
128127
{"2.6", "unusedLabel"},
129128
{"2.8", "unusedVariable"},
130129
{"5.3", "shadowVariable"},
@@ -168,7 +167,7 @@ std::vector<checkers::IdMapping> checkers::idMappingMisraCpp2008{
168167
{"5-0-16", "pointerOutOfBounds"},
169168
{"5-0-17", "comparePointers"},
170169
{"5-0-18", "comparePointers"},
171-
{"5-2-4", "cstyleCast"},
170+
{"5-2-4", "cstyleCast,dangerousTypeCast"},
172171
{"5-3-4", "sizeofFunctionCall"},
173172
{"5-8-1", "shiftTooManyBits"},
174173
{"6-6-5", "missingReturn"},

lib/checkexceptionsafety.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void CheckExceptionSafety::destructorsError(const Token * const tok, const std::
9595

9696
void CheckExceptionSafety::deallocThrow()
9797
{
98-
if (!mSettings->severity.isEnabled(Severity::warning))
98+
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("exceptDeallocThrow"))
9999
return;
100100

101101
logChecker("CheckExceptionSafety::deallocThrow"); // warning

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void CheckOther::warningDangerousTypeCast()
415415
// Only valid on C++ code
416416
if (!mTokenizer->isCPP())
417417
return;
418-
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("cstyleCast"))
418+
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("dangerousTypeCast"))
419419
return;
420420

421421
logChecker("CheckOther::warningDangerousTypeCast"); // warning,c++

lib/settings.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ static const std::set<std::string> autosarCheckers{
354354
"bufferAccessOutOfBounds",
355355
"comparePointers",
356356
"constParameter",
357-
"cstyleCast",
358357
"ctuOneDefinitionRuleViolation",
359358
"doubleFree",
360359
"duplInheritedMember",
@@ -396,7 +395,6 @@ static const std::set<std::string> autosarCheckers{
396395
"unsignedLessThanZero",
397396
"unusedFunction",
398397
"unusedStructMember",
399-
"unusedValue",
400398
"unusedVariable",
401399
"useInitializationList",
402400
"variableScope",
@@ -459,32 +457,65 @@ static const std::set<std::string> certCCheckers{
459457
static const std::set<std::string> certCppCheckers{
460458
"IOWithoutPositioning",
461459
"accessMoved",
460+
"argumentSize",
461+
"arrayIndexOutOfBounds",
462+
"arrayIndexOutOfBoundsCond",
463+
"arrayIndexThenCheck",
464+
"autoVariables",
465+
"autovarInvalidDeallocation",
466+
"bitwiseOnBoolean",
467+
"bufferAccessOutOfBounds",
462468
"comparePointers",
463469
"containerOutOfBounds",
464470
"ctuOneDefinitionRuleViolation",
465471
"danglingLifetime",
466472
"danglingReference",
467473
"danglingTempReference",
468474
"danglingTemporaryLifetime",
469-
"deallocThrow",
475+
"deallocret",
470476
"deallocuse",
471477
"doubleFree",
472478
"eraseDereference",
479+
"exceptDeallocThrow",
473480
"exceptThrowInDestructor",
481+
"floatConversionOverflow",
474482
"initializerList",
483+
"integerOverflow",
475484
"invalidContainer",
485+
"invalidFunctionArg",
486+
"invalidLengthModifierError",
487+
"invalidLifetime",
488+
"invalidScanfFormatWidth",
489+
"invalidscanf",
490+
"leakReturnValNotUsed",
491+
"leakUnsafeArgAlloc",
476492
"memleak",
493+
"memleakOnRealloc",
477494
"mismatchAllocDealloc",
478495
"missingReturn",
496+
"negativeIndex",
479497
"nullPointer",
498+
"nullPointerArithmetic",
499+
"nullPointerArithmeticRedundantCheck",
500+
"nullPointerDefaultArg",
501+
"nullPointerRedundantCheck",
502+
"objectIndex",
480503
"operatorEqToSelf",
504+
"pointerOutOfBounds",
505+
"pointerOutOfBoundsCond",
506+
"preprocessorErrorDirective",
507+
"resourceLeak",
481508
"returnDanglingLifetime",
482509
"sizeofCalculation",
510+
"stringLiteralWrite",
483511
"uninitStructMember",
484512
"uninitdata",
485513
"uninitvar",
514+
"useClosedFile",
486515
"virtualCallInConstructor",
487-
"virtualDestructor"
516+
"virtualDestructor",
517+
"wrongPrintfScanfArgNum",
518+
"wrongPrintfScanfParameterPositionError"
488519
};
489520

490521
static const std::set<std::string> misrac2012Checkers{
@@ -524,6 +555,7 @@ static const std::set<std::string> misrac2012Checkers{
524555
"unknownEvaluationOrder",
525556
"unreachableCode",
526557
"unreadVariable",
558+
"unusedFunction",
527559
"unusedLabel",
528560
"unusedVariable",
529561
"useClosedFile",
@@ -567,6 +599,7 @@ static const std::set<std::string> misrac2023Checkers{
567599
"unknownEvaluationOrder",
568600
"unreachableCode",
569601
"unreadVariable",
602+
"unusedFunction",
570603
"unusedLabel",
571604
"unusedVariable",
572605
"useClosedFile",
@@ -610,6 +643,7 @@ static const std::set<std::string> misrac2025Checkers{
610643
"unknownEvaluationOrder",
611644
"unreachableCode",
612645
"unreadVariable",
646+
"unusedFunction",
613647
"unusedLabel",
614648
"unusedVariable",
615649
"useClosedFile",
@@ -623,6 +657,7 @@ static const std::set<std::string> misracpp2008Checkers{
623657
"constVariable",
624658
"cstyleCast",
625659
"ctuOneDefinitionRuleViolation",
660+
"dangerousTypeCast",
626661
"danglingLifetime",
627662
"duplInheritedMember",
628663
"duplicateBreak",

0 commit comments

Comments
 (0)