From ce35a6c9751de98bb6dd67a645624f3825609040 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Thu, 21 Apr 2022 16:59:25 +0200 Subject: [PATCH] std.cfg: Added more tests for strcat() and strcpy(). --- test/cfg/std.c | 22 ++++++++++++++++++++++ test/cfg/std.cpp | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/test/cfg/std.c b/test/cfg/std.c index 6c0ec4f04..de5d47fec 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -3113,6 +3113,28 @@ void uninitvar_strcat(char *dest, const char * const source) (void)strcat(dest,source); } +void nullPointer_strcpy(char *dest, const char * const source) +{ + // cppcheck-suppress nullPointer + (void)strcpy(NULL,source); + // cppcheck-suppress nullPointer + (void)strcpy(dest,NULL); + + // no warning shall be shown for + (void)strcpy(dest,source); +} + +void nullPointer_strcat(char *dest, const char * const source) +{ + // cppcheck-suppress nullPointer + (void)strcat(NULL,source); + // cppcheck-suppress nullPointer + (void)strcat(dest,NULL); + + // no warning shall be shown for + (void)strcat(dest,source); +} + void bufferAccessOutOfBounds_strcat(char *dest, const char * const source) { char buf4[4] = {0}; diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 636340acf..1e063d502 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -1293,6 +1293,28 @@ void nullPointer_strncat(char *d, char *s, size_t n) (void)std::strncat(d,s,n); } +void nullPointer_strcpy(char *dest, const char * const source) +{ + // cppcheck-suppress nullPointer + (void)std::strcpy(NULL,source); + // cppcheck-suppress nullPointer + (void)std::strcpy(dest,NULL); + + // no warning shall be shown for + (void)std::strcpy(dest,source); +} + +void nullPointer_strcat(char *dest, const char * const source) +{ + // cppcheck-suppress nullPointer + (void)std::strcat(NULL,source); + // cppcheck-suppress nullPointer + (void)std::strcat(dest,NULL); + + // no warning shall be shown for + (void)std::strcat(dest,source); +} + void nullPointer_strncpy(char *d, const char *s, size_t n) { // cppcheck-suppress nullPointer