From 4e86debc5f2428cca792ba2b4bf924d91b350990 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 10 Jun 2024 22:30:34 +0200 Subject: [PATCH] Fix FP constParameterReference, bad heuristic --- cfg/std.cfg | 2 +- lib/astutils.cpp | 4 ---- lib/library.cpp | 4 ++++ test/cfg/std.cpp | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 0c9293c1cfa..a8e2cb3d13a 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -4861,7 +4861,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun false - + diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b2fc47fe4c7..c5a40d4fda5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2516,10 +2516,6 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti } if (Token::simpleMatch(tok->tokAt(-2), "std :: tie")) return true; - // if the library says 0 is invalid - // => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic) - if (indirect == 0 && requireNonNull) - return false; // possible pass-by-reference => inconclusive if (possiblyPassedByReference) { if (inconclusive != nullptr) diff --git a/lib/library.cpp b/lib/library.cpp index 07270b7e520..bd110060765 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -749,6 +749,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co if (const char* const argIndirect = functionnode->Attribute("indirect")) { const int indirect = strToInt(argIndirect); ac.direction[indirect] = dir; // TODO: handle multiple directions/indirect levels + if (dir == ArgumentChecks::Direction::DIR_OUT) { + for (int i = 0; i < indirect; ++i) + ac.direction[i] = ArgumentChecks::Direction::DIR_IN; // ptr is not modified if pointed-to data are written + } } else ac.direction.fill(dir); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index d11d9edb42d..27b41d6f93b 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -553,7 +553,6 @@ void bufferAccessOutOfBounds_std_ofstream_write(std::ofstream &os, const char* s (void)os.write(s,n); } -// cppcheck-suppress constParameterReference // TODO: FP void bufferAccessOutOfBounds_std_ifstream_get(std::ifstream& in, std::streambuf& sb) { char cBuf[10];