Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 19, 2024
2 parents b4ea5f7 + 49ce02f commit ecb4ee8
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 50 deletions.
4 changes: 4 additions & 0 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,9 @@ def misra_config(self, data):
end_token = tok.link
while tok != end_token:
tok = tok.next
if tok.str == 'sizeof' and tok.next.str == '(':
tok = tok.next.link
continue
if tok.str == "(" and tok.isCast:
tok = tok.link
continue
Expand Down Expand Up @@ -4254,6 +4257,7 @@ def setSuppressionList(self, suppressionlist):
self.addSuppressedRule(ruleNum)

def report_config_error(self, location, errmsg):
errmsg = 'Because of missing configuration, misra checking is incomplete. There can be false negatives! ' + errmsg
cppcheck_severity = 'error'
error_id = 'config'
if self.settings.verify:
Expand Down
10 changes: 10 additions & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,3 +2035,13 @@ static void misra_22_10(void)
f = strtod(inStr, NULL_PTR);
if(errno != 0) {}
}

// #12448
static void check_misra_config(void)
{
if (sizeof(struct bar) == 0U) {} //no warning
if (sizeof(int abc) == 0U) {} //no warning
if (sizeof(xyz) == 0U) {} //no warning
if (sizeof(const pqr) == 0U) {} //no warning
if (sizeof(const int* const pqrs) == 0U) {} //no-warning
}
44 changes: 38 additions & 6 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6428,7 +6428,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
std::istringstream& std::istringstream::get (char* s, streamsize n, char delim);
stream buffer (3) std::istringstream& std::istringstream::get (streambuf& sb);
std::istringstream& std::istringstream::get (streambuf& sb, char delim);-->
<!-- There is currently no way to define this properly because Cppcheck lacks support for
<!-- There is currently no way to define this properly because Cppcheck lacks support for
overloaded functions.-->
<function name="std::istream::get,std::istringstream::get">
<noreturn>false</noreturn>
Expand Down Expand Up @@ -6509,28 +6509,35 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<noreturn>false</noreturn>
</function>
<!-- bool good() const; -->
<function name="std::ios::good,std::ios_base::good,std::ostream::good,std::ofstream::good,std::ostringstream::good">
<function name="std::ios::good,std::ios_base::good,std::ostream::good,std::ofstream::good,std::ostringstream::good,std::ifstream::good,std::istringstream::good,std::wistringstream::good,std::basic_istringstream::good">
<use-retval/>
<const/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
</function>
<!-- bool eof() const; -->
<function name="std::ios::eof,std::ios_base::eof,std::ostream::eof,std::ofstream::eof,std::ostringstream::eof">
<function name="std::ios::eof,std::ios_base::eof,std::ostream::eof,std::ofstream::eof,std::ostringstream::eof,std::istringstream::eof,std::wistringstream::eof,std::basic_istringstream::eof">
<use-retval/>
<const/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
</function>
<!-- bool fail() const; -->
<function name="std::ios::fail,std::ios_base::fail,std::ostream::fail,std::ofstream::fail,std::ostringstream::fail">
<function name="std::ios::fail,std::ios_base::fail,std::ostream::fail,std::ofstream::fail,std::ostringstream::fail,std::ifstream::fail,std::istringstream::fail,std::wistringstream::fail,std::basic_istringstream::fail">
<use-retval/>
<const/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
</function>
<!-- bool bad() const; -->
<function name="std::ios::bad,std::ios_base::bad,std::ostream::bad,std::ofstream::bad,std::ostringstream::bad">
<function name="std::ios::bad,std::ios_base::bad,std::ostream::bad,std::ofstream::bad,std::ostringstream::bad,std::ifstream::bad,std::istringstream::bad,std::wistringstream::bad,std::basic_istringstream::bad">
<use-retval/>
<const/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
</function>
<!-- bool is_open() const; -->
<function name="std::basic_ifstream::is_open,std::ifstream::is_open,std::basic_ofstream::is_open,std::ofstream::is_open">
<use-retval/>
<const/>
<returnValue type="bool"/>
Expand Down Expand Up @@ -6566,6 +6573,31 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<valid>0:</valid>
</arg>
</function>
<!--https://en.cppreference.com/w/cpp/io/manip/quoted -->
<!--template< class CharT >
/*unspecified*/ quoted( const CharT* s,
CharT delim = CharT('"'), CharT escape = CharT('\\') ); (1)(since C++14)
template< class CharT, class Traits, class Allocator >
/*unspecified*/ quoted( const std::basic_string<CharT, Traits, Allocator>& s,
CharT delim = CharT('"'), CharT escape = CharT('\\') ); (2)(since C++14)
template< class CharT, class Traits>
/*unspecified*/ quoted( std::basic_string_view<CharT, Traits> s,
CharT delim = CharT('"'), CharT escape = CharT('\\') ); (3)(since C++17)
template< class CharT, class Traits, class Allocator >
/*unspecified*/ quoted( std::basic_string<CharT, Traits, Allocator>& s,
CharT delim=CharT('"'), CharT escape=CharT('\\') ); (4)(since C++14) -->
<function name="std::quoted">
<!-- This function returns an object of unspecified type -->
<leak-ignore/>
<noreturn>false</noreturn>
<arg nr="1" direction="in"/>
<arg nr="2" direction="in" default="&apos;&quot;&apos;">
<not-uninit/>
</arg>
<arg nr="3" direction="in" default="&apos;\\&apos;">
<not-uninit/>
</arg>
</function>
<!--std::ostream& std::ostream::write (const char* s, streamsize n);-->
<function name="std::ostream::write">
<returnValue type="std::ostream &amp;"/>
Expand Down Expand Up @@ -8303,7 +8335,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<not-bool/>
<strz/>
</arg>
</function>
</function>
<!-- int mtx_init( mtx_t* mutex, int type ); // since C11 -->
<function name="mtx_init">
<noreturn>false</noreturn>
Expand Down
120 changes: 117 additions & 3 deletions cfg/windows.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16895,8 +16895,6 @@ HFONT CreateFont(
<define name="SHUTDOWN_POWEROFF" value="0x00000008"/>
<define name="SHUTDOWN_RESTART" value="0x00000004"/>
<define name="SHUTDOWN_RESTARTAPPS" value="0x00000080"/>
<define name="KEY_WOW64_32KEY" value="0x0200"/>
<define name="KEY_WOW64_64KEY" value="0x0100"/>
<define name="RRF_RT_ANY" value="0x0000ffff"/>
<define name="RRF_RT_DWORD" value="0x00000018"/>
<define name="RRF_RT_QWORD" value="0x00000048"/>
Expand All @@ -16917,8 +16915,124 @@ HFONT CreateFont(
<define name="REG_NOTIFY_CHANGE_LAST_SET" value="0x00000004L"/>
<define name="REG_NOTIFY_CHANGE_SECURITY" value="0x00000008L"/>
<define name="REG_NOTIFY_THREAD_AGNOSTIC" value="0x10000000L"/>
<define name="REG_FORCE_RESTORE" value="0x00000008L"/>
<define name="REG_WHOLE_HIVE_VOLATILE" value="0x00000001L"/>
<define name="DOCKINFO_DOCKED" value="0x2"/>
<define name="DOCKINFO_UNDOCKED" value="0x1"/>
<define name="DOCKINFO_USER_DOCKED" value="0x5"/>
<define name="DOCKINFO_USER_SUPPLIED" value="0x4"/>
<define name="DOCKINFO_USER_UNDOCKED" value="0x6"/>
<define name="FCIERR_ALLOC_FAIL" value="0x03"/>
<define name="FCIERR_CAB_FILE" value="0x06"/>
<define name="FCIERR_CAB_FORMAT_LIMIT" value="0x09"/>
<define name="FCIERR_MCI_FAIL" value="0x08"/>
<define name="FCIERR_NONE" value="0x00"/>
<define name="FCIERR_OPEN_SRC" value="0x01"/>
<define name="FCIERR_READ_SRC" value="0x02"/>
<define name="FCIERR_TEMP_FILE" value="0x04"/>
<define name="FCIERR_USER_ABORT" value="0x07"/>
<define name="FDIERROR_ALLOC_FAIL" value="0x05"/>
<define name="FDIERROR_BAD_COMPR_TYPE" value="0x06"/>
<define name="FDIERROR_CABINET_NOT_FOUND" value="0x01"/>
<define name="FDIERROR_CORRUPT_CABINET" value="0x04"/>
<define name="FDIERROR_MDI_FAIL" value="0x07"/>
<define name="FDIERROR_NONE" value="0x00"/>
<define name="FDIERROR_NOT_A_CABINET" value="0x02"/>
<define name="FDIERROR_RESERVE_MISMATCH" value="0x09"/>
<define name="FDIERROR_TARGET_FILE" value="0x08"/>
<define name="FDIERROR_UNKNOWN_CABINET_VERSION" value="0x03"/>
<define name="FDIERROR_USER_ABORT" value="0x0B"/>
<define name="FDIERROR_WRONG_CABINET" value="0x0A"/>
<define name="FH_STATE_DISABLED_BY_GP" value="0x02"/>
<define name="FH_STATE_FATAL_CONFIG_ERROR" value="0x03"/>
<define name="FH_STATE_NOT_TRACKED" value="0x00"/>
<define name="FH_STATE_NO_ERROR" value="0xFF"/>
<define name="FH_STATE_OFF" value="0x01"/>
<define name="FH_STATE_STAGING_FULL" value="0x12"/>
<define name="FH_STATE_TARGET_ABSENT" value="0x15"/>
<define name="FH_STATE_TARGET_ACCESS_DENIED" value="0x0E"/>
<define name="FH_STATE_TARGET_FULL" value="0x11"/>
<define name="FH_STATE_TARGET_FULL_RETENTION_MAX" value="0x10"/>
<define name="FH_STATE_TARGET_LOW_SPACE" value="0x14"/>
<define name="FH_STATE_TARGET_LOW_SPACE_RETENTION_MAX" value="0x13"/>
<define name="FH_STATE_TARGET_VOLUME_DIRTY" value="0x0F"/>
<define name="FH_STATE_TOO_MUCH_BEHIND" value="0x16"/>
<define name="ICW_ALREADYRUN" value="0x0004"/>
<define name="ICW_CHECKSTATUS" value="0x0001"/>
<define name="ICW_FULLPRESENT" value="0x0001"/>
<define name="ICW_FULL_SMARTSTART" value="0x800"/>
<define name="ICW_LAUNCHEDFULL" value="0x0100"/>
<define name="ICW_LAUNCHEDMANUAL" value="0x0200"/>
<define name="ICW_LAUNCHFULL" value="0x0100"/>
<define name="ICW_LAUNCHMANUAL" value="0x0200"/>
<define name="ICW_MANUALPRESENT" value="0x0002"/>
<define name="ICW_USE_SHELLNEXT" value="0x0400"/>
<define name="KEY_WOW64_32KEY" value="0x0200"/>
<define name="KEY_WOW64_64KEY" value="0x0100"/>
<define name="NETLOGON_CONTROL_CHANGE_PASSWORD" value="9"/>
<define name="NETLOGON_CONTROL_FORCE_DNS_REG" value="11"/>
<define name="NETLOGON_CONTROL_PDC_REPLICATE" value="4"/>
<define name="NETLOGON_CONTROL_QUERY" value="1"/>
<define name="NETLOGON_CONTROL_QUERY_DNS_REG" value="12"/>
<define name="NETLOGON_CONTROL_REDISCOVER" value="5"/>
<define name="NETLOGON_CONTROL_REPLICATE" value="2"/>
<define name="NETLOGON_CONTROL_SYNCHRONIZE" value="3"/>
<define name="NETLOGON_CONTROL_TC_QUERY" value="6"/>
<define name="NETLOGON_CONTROL_TC_VERIFY" value="10"/>
<define name="NETLOGON_DNS_UPDATE_FAILURE" value="0x00000040"/>
<define name="NETLOGON_FULL_SYNC_REPLICATION" value="0x00000004"/>
<define name="NETLOGON_HAS_IP" value="0x00000010"/>
<define name="NETLOGON_HAS_TIMESERV" value="0x00000020"/>
<define name="NETLOGON_REDO_NEEDED" value="0x00000008"/>
<define name="NETLOGON_REPLICATION_IN_PROGRESS" value="0x00000002"/>
<define name="NETLOGON_REPLICATION_NEEDED" value="0x00000001"/>
<define name="NETLOGON_VERIFY_STATUS_RETURNED" value="0x00000080"/>
<define name="REG_FORCE_RESTORE" value="0x00000008L"/>
<define name="REG_LATEST_FORMAT" value="2"/>
<define name="REG_NO_COMPRESSION" value="4"/>
<define name="REG_STANDARD_FORMAT" value="1"/>
<define name="SSRVACTION_EVENT" value="3"/>
<define name="SSRVACTION_QUERYCANCEL" value="2"/>
<define name="SSRVACTION_SIZE" value="5"/>
<define name="SSRVACTION_TRACE" value="1"/>
<define name="VARIABLE_ATTRIBUTE_APPEND_WRITE" value="0x00000040"/>
<define name="VARIABLE_ATTRIBUTE_AUTHENTICATED_WRITE_ACCESS" value="0x00000010"/>
<define name="VARIABLE_ATTRIBUTE_BOOTSERVICE_ACCESS" value="0x00000002"/>
<define name="VARIABLE_ATTRIBUTE_HARDWARE_ERROR_RECORD" value="0x00000008"/>
<define name="VARIABLE_ATTRIBUTE_NON_VOLATILE" value="0x00000001"/>
<define name="VARIABLE_ATTRIBUTE_RUNTIME_ACCESS" value="0x00000004"/>
<define name="VARIABLE_ATTRIBUTE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS" value="0x00000020"/>
<define name="VER_BUILDNUMBER" value="0x0000004"/>
<define name="VER_EQUAL" value="1"/>
<define name="VER_GREATER" value="2"/>
<define name="VER_GREATER_EQUAL" value="3"/>
<define name="VER_LESS" value="4"/>
<define name="VER_LESS_EQUAL" value="5"/>
<define name="VER_MAJORVERSION" value="0x0000002"/>
<define name="VER_MINORVERSION" value="0x0000001"/>
<define name="VER_NT_DOMAIN_CONTROLLER" value="0x0000002"/>
<define name="VER_NT_SERVER" value="0x0000003"/>
<define name="VER_NT_WORKSTATION" value="0x0000001"/>
<define name="VER_OR" value="7"/>
<define name="VER_PLATFORMID" value="0x0000008"/>
<define name="VER_PLATFORM_WIN32_NT" value="2"/>
<define name="VER_PRODUCT_TYPE" value="0x0000080"/>
<define name="VER_SERVICEPACKMAJOR" value="0x0000020"/>
<define name="VER_SERVICEPACKMINOR" value="0x0000010"/>
<define name="VER_SUITENAME" value="0x0000040"/>
<define name="VER_SUITE_BACKOFFICE" value="0x00000004"/>
<define name="VER_SUITE_BLADE" value="0x00000400"/>
<define name="VER_SUITE_COMPUTE_SERVER" value="0x00004000"/>
<define name="VER_SUITE_DATACENTER" value="0x00000080"/>
<define name="VER_SUITE_EMBEDDEDNT" value="0x00000040"/>
<define name="VER_SUITE_ENTERPRISE" value="0x00000002"/>
<define name="VER_SUITE_MULTIUSERTS" value="0x00020000"/>
<define name="VER_SUITE_PERSONAL" value="0x00000200"/>
<define name="VER_SUITE_SINGLEUSERTS" value="0x00000100"/>
<define name="VER_SUITE_SMALLBUSINESS" value="0x00000001"/>
<define name="VER_SUITE_SMALLBUSINESS_RESTRICTED" value="0x00000020"/>
<define name="VER_SUITE_STORAGE_SERVER" value="0x00002000"/>
<define name="VER_SUITE_TERMINAL" value="0x00000010"/>
<define name="VER_SUITE_WH_SERVER" value="0x00008000"/>
<!-- https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol -->
<entrypoint name="mainCRTStartup"/>
<entrypoint name="WinMain"/>
Expand Down
5 changes: 5 additions & 0 deletions createrelease
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#
# check every isPremiumEnabled call:
# - every id should be in --errorlist
# git grep 'isPremiumEnabled[(]"' | sed 's/.*isPremiumEnabled[(]"//' | sed 's/".*//' | sort | uniq > ids1.txt
# ./cppcheck --errorlist | grep ' id="' | sed 's/.* id="//' | sed 's/".*//' | sort | uniq > ids2.txt
# diff -y ids1.txt ids2.txt
# - premiumaddon: check coverage.py
# python3 coverage.py --id ; sort ids-*.txt | uniq > ~/cppcheck/ids3.txt
# diff -y ids2.txt ids3.txt
#
# Windows installer:
# - ensure latest build was successful
Expand Down
2 changes: 1 addition & 1 deletion lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void CheckFunctions::useStandardLibrary()
continue;

// 3. we expect idx incrementing by 1
const bool inc = stepToken->str() == "++" && stepToken->astOperand1()->varId() == idxVarId;
const bool inc = stepToken->str() == "++" && stepToken->astOperand1() && stepToken->astOperand1()->varId() == idxVarId;
const bool plusOne = stepToken->isBinaryOp() && stepToken->str() == "+=" &&
stepToken->astOperand1()->varId() == idxVarId &&
stepToken->astOperand2()->str() == "1";
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ void CheckOther::checkIncompleteStatement()
continue;
if (isVoidStmt(tok))
continue;
if (mTokenizer->isCPP() && tok->str() == "&" && !(tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral()))
if (mTokenizer->isCPP() && tok->str() == "&" && !(tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral()))
// Possible archive
continue;
const bool inconclusive = tok->isConstOp();
Expand Down
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, const Library&
if (Token::Match((derefValue ? derefValue : vartok)->astParent(), "(|=") && astIsRhs(derefValue ? derefValue : vartok)) {
const Token *rhstok = derefValue ? derefValue : vartok;
const Token *lhstok = rhstok->astParent()->astOperand1();
const Variable *lhsvar = lhstok->variable();
const Variable *lhsvar = lhstok ? lhstok->variable() : nullptr;
if (lhsvar && lhsvar->isReference() && lhsvar->nameToken() == lhstok)
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Toke
else
pm.setIntValue(tok, 0, then);
}
} else if (tok->exprId() > 0) {
} else if (tok && tok->exprId() > 0) {
if (endTok && findExpressionChanged(tok, tok->next(), endTok, settings, true))
return;
pm.setIntValue(tok, 0, then);
Expand Down
8 changes: 8 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4281,6 +4281,14 @@ void SymbolDatabase::printXml(std::ostream &out) const
outs += accessControlToString(function->access);
outs +="\"";
}
if (function->isOperator())
outs += " isOperator=\"true\"";
if (function->isExplicit())
outs += " isExplicit=\"true\"";
if (function->hasOverrideSpecifier())
outs += " hasOverrideSpecifier=\"true\"";
if (function->hasFinalSpecifier())
outs += " hasFinalSpecifier=\"true\"";
if (function->isInlineKeyword())
outs += " isInlineKeyword=\"true\"";
if (function->isStatic())
Expand Down
5 changes: 4 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ namespace {
Token* const tok2 = insertTokens(tok, rangeType);
Token* const tok3 = insertTokens(tok2, mRangeTypeQualifiers);

tok2->originalName(tok->str());
tok3->originalName(tok->str());
Token *after = tok3;
while (Token::Match(after, "%name%|*|&|&&|::"))
after = after->next();
Expand Down Expand Up @@ -6342,7 +6344,8 @@ void Tokenizer::removeMacrosInGlobalScope()
while (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName())
tok2 = tok2->linkAt(1)->next();

if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && !Token::Match(tok2, "namespace|class|struct|union|private:|protected:|public:"))
if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") &&
!Token::Match(tok2, "requires|namespace|class|struct|union|private:|protected:|public:"))
unknownMacroError(tok);

if (Token::Match(tok, "%type% (") && Token::Match(tok2, "%type% (") && !Token::Match(tok2, "noexcept|throw") && isFunctionHead(tok2->next(), ":;{"))
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
Token* const curlyBracket = squareBracket->link()->next();
squareBracket->astOperand1(curlyBracket);
state.op.push(squareBracket);
tok = curlyBracket->link()->next();
tok = curlyBracket->link() ? curlyBracket->link()->next() : nullptr;
continue;
}
}
Expand Down
Loading

0 comments on commit ecb4ee8

Please sign in to comment.