Skip to content

Commit

Permalink
Fix #12134 false negative: passedByValue (danmar#5607)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 31, 2023
1 parent c2d5aef commit 67b61a0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6977,6 +6977,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function>
<function name="std::string::substr">
<use-retval/>
<const/>
<returnValue type="std::string"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
Expand All @@ -6990,6 +6991,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function>
<function name="std::wstring::substr">
<use-retval/>
<const/>
<returnValue type="std::wstring"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
Expand All @@ -7003,6 +7005,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</function>
<function name="std::basic_string::substr">
<use-retval/>
<const/>
<returnValue type="std::basic_string"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.emplace_back(shadowed, "Shadowed declaration");
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class CPPCHECKLIB CheckOther : public Check {
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 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 knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value);
void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2);
Expand Down
7 changes: 7 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4638,6 +4638,13 @@ void string_view_unused(std::string_view v)
v.substr(1, 3);
}

// cppcheck-suppress passedByValue
void string_substr(std::string s)
{
// cppcheck-suppress ignoredReturnValue
s.substr(1, 3);
}

void stdspan()
{
#ifndef __cpp_lib_span
Expand Down

0 comments on commit 67b61a0

Please sign in to comment.