Skip to content

Commit 4e86deb

Browse files
committed
Fix FP constParameterReference, bad heuristic
1 parent d33d29c commit 4e86deb

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

cfg/std.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -4861,7 +4861,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
48614861
<noreturn>false</noreturn>
48624862
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" strlen-arg="2"/>
48634863
<leak-ignore/>
4864-
<arg nr="1" direction="out">
4864+
<arg nr="1" direction="out" indirect="1">
48654865
<not-null/>
48664866
<minsize type="strlen" arg="2"/>
48674867
</arg>

lib/astutils.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -2516,10 +2516,6 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
25162516
}
25172517
if (Token::simpleMatch(tok->tokAt(-2), "std :: tie"))
25182518
return true;
2519-
// if the library says 0 is invalid
2520-
// => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic)
2521-
if (indirect == 0 && requireNonNull)
2522-
return false;
25232519
// possible pass-by-reference => inconclusive
25242520
if (possiblyPassedByReference) {
25252521
if (inconclusive != nullptr)

lib/library.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
749749
if (const char* const argIndirect = functionnode->Attribute("indirect")) {
750750
const int indirect = strToInt<int>(argIndirect);
751751
ac.direction[indirect] = dir; // TODO: handle multiple directions/indirect levels
752+
if (dir == ArgumentChecks::Direction::DIR_OUT) {
753+
for (int i = 0; i < indirect; ++i)
754+
ac.direction[i] = ArgumentChecks::Direction::DIR_IN; // ptr is not modified if pointed-to data are written
755+
}
752756
}
753757
else
754758
ac.direction.fill(dir);

test/cfg/std.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ void bufferAccessOutOfBounds_std_ofstream_write(std::ofstream &os, const char* s
553553
(void)os.write(s,n);
554554
}
555555

556-
// cppcheck-suppress constParameterReference // TODO: FP
557556
void bufferAccessOutOfBounds_std_ifstream_get(std::ifstream& in, std::streambuf& sb)
558557
{
559558
char cBuf[10];

0 commit comments

Comments
 (0)