Skip to content

Commit b587c7c

Browse files
Fix #14866 FP bufferAccessOutOfBounds with vector and gethostname() (#8667)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent e0014e1 commit b587c7c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ ValueFlow::Value CheckBufferOverrunImpl::getBufferSize(const Token *bufTok) cons
574574
return *value;
575575
}
576576

577-
if (!var || var->isPointer())
577+
if (!var || var->isPointer() || (astIsContainer(bufTok) && var->getTypeName() != "std::array"))
578578
return ValueFlow::Value(-1);
579579

580580
const MathLib::bigint dim = std::accumulate(var->dimensions().cbegin(), var->dimensions().cend(), MathLib::bigint(1), [](MathLib::bigint i1, const Dimension &dim) {

test/testbufferoverrun.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,12 @@ class TestBufferOverrun : public TestFixture {
35393539
"[test.cpp:7:12]: (error) Buffer is accessed out of bounds: &a[0][0] [bufferAccessOutOfBounds]\n",
35403540
"",
35413541
errout_str());
3542+
3543+
check("void f() {\n" // #14866
3544+
" std::vector<char> buf(25);\n"
3545+
" std::memset(&buf[0], 0, 25);\n"
3546+
"}\n");
3547+
ASSERT_EQUALS("", errout_str());
35423548
}
35433549

35443550
void buffer_overrun_errorpath() {

0 commit comments

Comments
 (0)