diff --git a/test/cfg/std.c b/test/cfg/std.c index 97fef1fbb..b19b85378 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -2697,6 +2697,15 @@ void uninitvar_memchr(void) (void)memchr(cs,c,n); } +void *bufferAccessOutOfBounds_memchr(const void *s, int c, size_t n) +{ + char buf[42]={0}; + (void)memchr(buf,c,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)memchr(buf,c,43); + return memchr(s,c,n); +} + void uninitvar_wmemchr(void) { wchar_t *cs; diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index d6e3bf460..ebda59a51 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -32,6 +32,15 @@ #include #include +void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n) +{ + char buf[42]={0}; + (void)std::memchr(buf,c,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)std::memchr(buf,c,43); + return std::memchr(s,c,n); +} + // As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h. #ifdef __STDC_LIB_EXT1__ void uninitvar_localtime_s(const std::time_t *restrict time, struct tm *restrict result)