From f62d9d585324de5ecfc347a46a1ed0eb96b11c1e Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Tue, 13 Apr 2021 19:13:00 +0200 Subject: [PATCH] std.cfg: Fixed bufferAccessOutOfBounds false negative for strncmp(). --- cfg/std.cfg | 4 ++++ test/cfg/std.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/cfg/std.cfg b/cfg/std.cfg index 96fcc9a47..95a1504c3 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -5000,10 +5000,14 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + + + + diff --git a/test/cfg/std.c b/test/cfg/std.c index a5e60d3f1..49bc0f43f 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -3561,6 +3561,17 @@ void bufferAccessOutOfBounds_strxfrm(void) (void)strxfrm(dest,src,3); } +void bufferAccessOutOfBounds_strncmp(void) +{ + const char src[3] = "abc"; + char dest[1] = "a"; + (void)strncmp(dest,src,1); + // cppcheck-suppress bufferAccessOutOfBounds + (void)strncmp(dest,src,2); + // cppcheck-suppress bufferAccessOutOfBounds + (void)strncmp(dest,src,3); +} + void uninitvar_wcsxfrm(void) { wchar_t *ds;