Added tests for overlapping data.

This commit is contained in:
orbitcowboy 2021-07-10 18:28:26 +02:00
parent 021a72f84b
commit 7ad64891ea
3 changed files with 60 additions and 2 deletions

View File

@ -27,6 +27,14 @@
#include <ctype.h> #include <ctype.h>
#include <stdbool.h> #include <stdbool.h>
void overlappingWriteFunction_swab(char *src, char *dest, ssize_t n)
{
// No warning shall be shown:
swab(dest, src, n);
// cppcheck-suppress overlappingWriteFunction
swab(src, src+3, 4);
}
bool invalidFunctionArgBool_isascii(bool b, int c) bool invalidFunctionArgBool_isascii(bool b, int c)
{ {
// cppcheck-suppress invalidFunctionArgBool // cppcheck-suppress invalidFunctionArgBool

View File

@ -30,6 +30,22 @@
#include <functional> #include <functional>
#include <bitset> #include <bitset>
void overlappingWriteFunction_wcscat(wchar_t *src, wchar_t *dest)
{
// No warning shall be shown:
(void)wcscat(dest, src);
// cppcheck-suppress overlappingWriteFunction
(void)wcscat(src, src);
}
char * overlappingWriteFunction_strcat(char *src, char *dest)
{
// No warning shall be shown:
(void)strcat(dest, src);
// cppcheck-suppress overlappingWriteFunction
return strcat(src, src);
}
wchar_t * overlappingWriteFunction_wcscpy(wchar_t *src, wchar_t *dest) wchar_t * overlappingWriteFunction_wcscpy(wchar_t *src, wchar_t *dest)
{ {
// No warning shall be shown: // No warning shall be shown:
@ -59,6 +75,13 @@ char * overlappingWriteFunction_strncpy(char *buf, const std::size_t count)
return strncpy(&buf[0], &buf[3], 4U); return strncpy(&buf[0], &buf[3], 4U);
} }
void * overlappingWriteFunction_memmove(void)
{
// No warning shall be shown:
char str[] = "memmove handles overlapping data well";
return memmove(str,str+3,4);
}
std::bitset<10> std_bitset_test_ignoredReturnValue() std::bitset<10> std_bitset_test_ignoredReturnValue()
{ {
std::bitset<10> b1("1111010000"); std::bitset<10> b1("1111010000");

View File

@ -11,6 +11,27 @@
#include <direct.h> #include <direct.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <memory.h>
#include <mbstring.h>
unsigned char * overlappingWriteFunction__mbscat(unsigned char *src, unsigned char *dest)
{
// No warning shall be shown:
(void)_mbscat(dest, src);
// cppcheck-suppress overlappingWriteFunction
return _mbscat(src, src);
}
unsigned char * overlappingWriteFunction__memccpy(unsigned char *src, unsigned char *dest, int c, size_t count)
{
// No warning shall be shown:
(void)_memccpy(dest, src, c, count);
(void)_memccpy(dest, src, 42, count);
// cppcheck-suppress overlappingWriteFunction
(void) _memccpy(dest, dest, c, 4);
// cppcheck-suppress overlappingWriteFunction
return _memccpy(dest, dest+3, c, 4);
}
unsigned char * overlappingWriteFunction__mbscpy(unsigned char *src, unsigned char *dest) unsigned char * overlappingWriteFunction__mbscpy(unsigned char *src, unsigned char *dest)
{ {
@ -20,6 +41,14 @@ unsigned char * overlappingWriteFunction__mbscpy(unsigned char *src, unsigned ch
return _mbscpy(src, src); return _mbscpy(src, src);
} }
void overlappingWriteFunction__swab(char *src, char *dest, int n)
{
// No warning shall be shown:
_swab(dest, src, n);
// cppcheck-suppress overlappingWriteFunction
_swab(src, src+3, 4);
}
SYSTEM_INFO uninitvar_GetSystemInfo(char * envstr) SYSTEM_INFO uninitvar_GetSystemInfo(char * envstr)
{ {
// No warning is expected // No warning is expected
@ -877,8 +906,6 @@ unsigned char * uninitvar_mbscat(unsigned char *strDestination, const unsigned c
(void)_mbscat(uninit_deststr,uninit_srcstr); (void)_mbscat(uninit_deststr,uninit_srcstr);
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
(void)_mbscat(strDestination,uninit_srcstr); (void)_mbscat(strDestination,uninit_srcstr);
// cppcheck-suppress uninitvar
(void)_mbscat(uninit_deststr,uninit_deststr);
// no warning shall be shown for // no warning shall be shown for
return _mbscat(strDestination,strSource); return _mbscat(strDestination,strSource);