Skip to content

Commit

Permalink
Fix #12824 internalError due to bad indirect value (danmar#6497)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jun 9, 2024
1 parent 1638831 commit 99674e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 9 additions & 0 deletions test/cfg/std.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5070,3 +5070,8 @@ void constVariablePointer_push_back(std::vector<T*>& d, const std::vector<T*>& s
d.push_back(newE);
}
}

// cppcheck-suppress constParameterReference
void constParameterReference_push_back(std::vector<std::string>& v, std::string& s) { // #12661
v.push_back(s);
}

0 comments on commit 99674e1

Please sign in to comment.