std.cfg: Added support for wcsncpy regarding data-overlapping

This commit is contained in:
orbitcowboy 2021-07-09 16:32:54 +02:00
parent 0d96772304
commit 652e2765bc
2 changed files with 15 additions and 2 deletions

View File

@ -5238,6 +5238,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<returnValue type="wchar_t *"/> <returnValue type="wchar_t *"/>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" size-arg="3"/>
<arg nr="1"> <arg nr="1">
<not-null/> <not-null/>
<minsize type="argvalue" arg="3"/> <minsize type="argvalue" arg="3"/>

View File

@ -30,10 +30,22 @@
#include <functional> #include <functional>
#include <bitset> #include <bitset>
char * overlappingWriteFunction_strncpy(char *buf) wchar_t * overlappingWriteFunction_wcsncpy(wchar_t *buf, const std::size_t count)
{ {
// No warning shall be shown:
(void)wcsncpy(&buf[0], &buf[3], count); // size is not known
(void)wcsncpy(&buf[0], &buf[3], 3U); // no-overlap
// cppcheck-suppress overlappingWriteFunction // cppcheck-suppress overlappingWriteFunction
return strncpy(&buf[0], &buf[3], 5U); return wcsncpy(&buf[0], &buf[3], 4U);
}
char * overlappingWriteFunction_strncpy(char *buf, const std::size_t count)
{
// No warning shall be shown:
(void)strncpy(&buf[0], &buf[3], count); // size is not known
(void)strncpy(&buf[0], &buf[3], 3U); // no-overlap
// cppcheck-suppress overlappingWriteFunction
return strncpy(&buf[0], &buf[3], 4U);
} }
std::bitset<10> std_bitset_test_ignoredReturnValue() std::bitset<10> std_bitset_test_ignoredReturnValue()