Skip to content

Commit 6f6ddb9

Browse files
committed
std.cfg: Improved tests for memchr().
1 parent e9a0d79 commit 6f6ddb9

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

test/cfg/std.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,15 @@ void uninitvar_memchr(void)
26972697
(void)memchr(cs,c,n);
26982698
}
26992699

2700+
void *bufferAccessOutOfBounds_memchr(const void *s, int c, size_t n)
2701+
{
2702+
char buf[42]={0};
2703+
(void)memchr(buf,c,42);
2704+
// cppcheck-suppress bufferAccessOutOfBounds
2705+
(void)memchr(buf,c,43);
2706+
return memchr(s,c,n);
2707+
}
2708+
27002709
void uninitvar_wmemchr(void)
27012710
{
27022711
wchar_t *cs;

test/cfg/std.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
#include <iterator>
3333
#include <vector>
3434

35+
void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n)
36+
{
37+
char buf[42]={0};
38+
(void)std::memchr(buf,c,42);
39+
// cppcheck-suppress bufferAccessOutOfBounds
40+
(void)std::memchr(buf,c,43);
41+
return std::memchr(s,c,n);
42+
}
43+
3544
// 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.
3645
#ifdef __STDC_LIB_EXT1__
3746
void uninitvar_localtime_s(const std::time_t *restrict time, struct tm *restrict result)

0 commit comments

Comments
 (0)