Skip to content

Commit e683f3c

Browse files
committed
std.cfg: Added more test for strncpy().
1 parent 7f48127 commit e683f3c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

test/cfg/std.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,16 @@ void nullPointer_strncat(char *d, char *s, size_t n)
34593459
(void)strncat(d,s,n);
34603460
}
34613461

3462+
void nullPointer_strncpy(char *d, const char *s, size_t n)
3463+
{
3464+
// cppcheck-suppress nullPointer
3465+
(void)strncpy(NULL,s,n);
3466+
// cppcheck-suppress nullPointer
3467+
(void)strncpy(d,NULL,n);
3468+
// no warning is expected for
3469+
(void)strncpy(d,s,n);
3470+
}
3471+
34623472
// errno_t strcat_s(char *restrict dest, rsize_t destsz, const char *restrict src); // since C11
34633473
void uninitvar_strcat_s(char *Ct, size_t N, char *S)
34643474
{

test/cfg/std.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,16 @@ void nullPointer_strncat(char *d, char *s, size_t n)
12931293
(void)std::strncat(d,s,n);
12941294
}
12951295

1296+
void nullPointer_strncpy(char *d, const char *s, size_t n)
1297+
{
1298+
// cppcheck-suppress nullPointer
1299+
(void)std::strncpy(NULL,s,n);
1300+
// cppcheck-suppress nullPointer
1301+
(void)std::strncpy(d,NULL,n);
1302+
// no warning is expected for
1303+
(void)std::strncpy(d,s,n);
1304+
}
1305+
12961306
void nullPointer_strncmp(const char *s1, const char *s2, size_t n)
12971307
{
12981308
// cppcheck-suppress nullPointer

0 commit comments

Comments
 (0)