From 99674e1bb1963259280a7a455736ab7d389a03c4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 9 Jun 2024 12:49:49 +0200 Subject: [PATCH] Fix #12824 internalError due to bad indirect value (#6497) --- lib/library.cpp | 2 +- test/cfg/std.c | 9 +++++++++ test/cfg/std.cpp | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/library.cpp b/lib/library.cpp index 4d6ae5a4eb3..07270b7e520 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1512,7 +1512,7 @@ Library::ArgumentChecks::Direction Library::getArgDirection(const Token* ftok, i const ArgumentChecks* arg = getarg(ftok, argnr); if (arg) { if (indirect < 0 || indirect >= arg->direction.size()) - throw InternalError(ftok, "Bad indirect value: " + std::to_string(indirect)); + return ArgumentChecks::Direction::DIR_UNKNOWN; // TODO: don't generate bad indirect values return arg->direction[indirect]; } if (formatstr_function(ftok)) { diff --git a/test/cfg/std.c b/test/cfg/std.c index f795cdc5bda..193339e9a58 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -320,6 +320,15 @@ void bufferAccessOutOfBounds_libraryDirectionConfiguration(void) arr[c] = 'x'; } +void internalError_libraryDirectionConfiguration(char* str) { // #12824 + const char* s = str; + char* end = str; + if (1) { + // cppcheck-suppress unreadVariable + unsigned long val = strtoul(&s[1], &end, 10); + } +} + void arrayIndexOutOfBounds() { char * pAlloc1 = aligned_alloc(8, 16); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 0e1f205d2cb..d11d9edb42d 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -5070,3 +5070,8 @@ void constVariablePointer_push_back(std::vector& d, const std::vector& s d.push_back(newE); } } + +// cppcheck-suppress constParameterReference +void constParameterReference_push_back(std::vector& v, std::string& s) { // #12661 + v.push_back(s); +}