Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 15 additions & 1 deletion lib/ctu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,20 @@ static bool findPath(const std::string &callId,
return false;
}

static std::string getInvalidValueString(CTU::FileInfo::InvalidValueType invalidValue)
{
using InvalidValueType = CTU::FileInfo::InvalidValueType;
switch (invalidValue) {
case InvalidValueType::null:
return "null";
case InvalidValueType::uninit:
return "uninitialized";
case InvalidValueType::bufferOverflow:
return "accessed out of bounds";
}
cppcheck::unreachable();
}

std::list<ErrorMessage::FileLocation> CTU::FileInfo::getErrorPath(InvalidValueType invalidValue,
const CTU::FileInfo::UnsafeUsage &unsafeUsage,
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> &callsMap,
Expand All @@ -581,7 +595,7 @@ std::list<ErrorMessage::FileLocation> CTU::FileInfo::getErrorPath(InvalidValueTy

std::list<ErrorMessage::FileLocation> locationList;

const std::string value1 = (invalidValue == InvalidValueType::null) ? "null" : "uninitialized";
const std::string value1 = getInvalidValueString(invalidValue);

for (int index = 9; index >= 0; index--) {
if (!path[index])
Expand Down
13 changes: 13 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5515,6 +5515,19 @@ class TestBufferOverrun : public TestFixture {
" f(s);\n"
"}\n");
ASSERT_EQUALS("", errout_str());

setMultiline();
ctu("void g(char* p) {\n"
" memset(p + 10, 0, 10);\n"
"}\n"
"void f() {\n"
" char a[10] = {};\n"
" g(a);\n"
"}");
ASSERT_EQUALS("[test.cpp:2:12]: error: Pointer arithmetic overflow; 'p' buffer size is 10 [ctuPointerArith]\n"
"[test.cpp:6:6]: note: Calling function g, 1st argument is accessed out of bounds\n"
"[test.cpp:2:12]: note: Using argument p\n",
errout_str());
}

void objectIndex() {
Expand Down
Loading