overlapping data; use the size value given by size-arg
This commit is contained in:
parent
ce58748690
commit
86f1acc223
|
@ -3462,6 +3462,7 @@ void CheckOther::checkOverlappingWrite()
|
|||
}
|
||||
if (!args[nonOverlappingData->sizeArg-1]->hasKnownIntValue())
|
||||
continue;
|
||||
const MathLib::bigint sizeValue = args[nonOverlappingData->sizeArg-1]->getKnownIntValue();
|
||||
const Token *buf1, *buf2;
|
||||
MathLib::bigint offset1, offset2;
|
||||
if (!getBufAndOffset(ptr1, &buf1, &offset1))
|
||||
|
@ -3469,6 +3470,11 @@ void CheckOther::checkOverlappingWrite()
|
|||
if (!getBufAndOffset(ptr2, &buf2, &offset2))
|
||||
continue;
|
||||
|
||||
if (offset1 < offset2 && offset1 + sizeValue <= offset2)
|
||||
continue;
|
||||
if (offset2 < offset1 && offset2 + sizeValue <= offset1)
|
||||
continue;
|
||||
|
||||
ErrorPath errorPath;
|
||||
const bool macro = true;
|
||||
const bool pure = true;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
char * overlappingWriteFunction_strncpy(char *buf)
|
||||
{
|
||||
// cppcheck-suppress overlappingWriteFunction
|
||||
return strncpy(&buf[0], &buf[3], 2U);
|
||||
return strncpy(&buf[0], &buf[3], 5U);
|
||||
}
|
||||
|
||||
std::bitset<10> std_bitset_test_ignoredReturnValue()
|
||||
|
|
|
@ -9343,6 +9343,12 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" char a[8];\n"
|
||||
" memcpy(&a[0], &a[4], 4u);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// wmemcpy
|
||||
check("void foo() {\n"
|
||||
" wchar_t a[10];\n"
|
||||
|
|
Loading…
Reference in New Issue