Fix #12134 false negative: passedByValue (#5607)

This commit is contained in:
chrchr-github 2023-10-31 19:08:08 +01:00 committed by GitHub
parent c2d5aef435
commit 67b61a0ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 2 deletions

View File

@ -6977,6 +6977,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function> </function>
<function name="std::string::substr"> <function name="std::string::substr">
<use-retval/> <use-retval/>
<const/>
<returnValue type="std::string"/> <returnValue type="std::string"/>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<arg nr="1" default="0" direction="in"> <arg nr="1" default="0" direction="in">
@ -6990,6 +6991,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function> </function>
<function name="std::wstring::substr"> <function name="std::wstring::substr">
<use-retval/> <use-retval/>
<const/>
<returnValue type="std::wstring"/> <returnValue type="std::wstring"/>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<arg nr="1" default="0" direction="in"> <arg nr="1" default="0" direction="in">
@ -7003,6 +7005,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function> </function>
<function name="std::basic_string::substr"> <function name="std::basic_string::substr">
<use-retval/> <use-retval/>
<const/>
<returnValue type="std::basic_string"/> <returnValue type="std::basic_string"/>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<arg nr="1" default="0" direction="in"> <arg nr="1" default="0" direction="in">

View File

@ -3596,7 +3596,7 @@ void CheckOther::checkShadowVariables()
} }
} }
void CheckOther::shadowError(const Token *var, const Token *shadowed, std::string type) void CheckOther::shadowError(const Token *var, const Token *shadowed, const std::string& type)
{ {
ErrorPath errorPath; ErrorPath errorPath;
errorPath.emplace_back(shadowed, "Shadowed declaration"); errorPath.emplace_back(shadowed, "Shadowed declaration");

View File

@ -284,7 +284,7 @@ private:
void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive); void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive);
void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition); void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition);
void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions); void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
void shadowError(const Token *var, const Token *shadowed, std::string type); void shadowError(const Token *var, const Token *shadowed, const std::string& type);
void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden); void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden);
void knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value); void knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value);
void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2); void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2);

View File

@ -4638,6 +4638,13 @@ void string_view_unused(std::string_view v)
v.substr(1, 3); v.substr(1, 3);
} }
// cppcheck-suppress passedByValue
void string_substr(std::string s)
{
// cppcheck-suppress ignoredReturnValue
s.substr(1, 3);
}
void stdspan() void stdspan()
{ {
#ifndef __cpp_lib_span #ifndef __cpp_lib_span