Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ static const ValueFlow::Value *getBufferSizeValue(const Token *tok)
auto it = std::find_if(tokenValues.cbegin(), tokenValues.cend(), std::mem_fn(&ValueFlow::Value::isBufferSizeValue));
if (it != tokenValues.cend())
return &*it;
it = std::find_if(tokenValues.cbegin(), tokenValues.cend(), std::mem_fn(&ValueFlow::Value::isContainerSizeValue));
it = std::find_if(tokenValues.cbegin(), tokenValues.cend(), [](const ValueFlow::Value& v) {
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
return v.isContainerSizeValue() && v.isKnown();
Comment thread
chrchr-github marked this conversation as resolved.
Outdated
});
return it == tokenValues.cend() ? nullptr : &*it;
}

Expand Down
8 changes: 8 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3564,6 +3564,14 @@ class TestBufferOverrun : public TestFixture {
" memset(&a[i], 0, sizeof(a));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4:16]: (error) Buffer is accessed out of bounds: &a[i] [bufferAccessOutOfBounds]\n", errout_str());

check("void f(const std::vector<uint8_t>& s) {\n" // #14948
" if (s.size() < 4)\n"
" return;\n"
" uint32_t u = 0;\n"
" std::memcpy(&u, &s[0], sizeof(u));\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void buffer_overrun_errorpath() {
Expand Down
Loading