From 316475f79f63b2726bc3ba3d85cb1cce91f2d546 Mon Sep 17 00:00:00 2001 From: versat Date: Thu, 21 Mar 2019 09:25:42 +0100 Subject: [PATCH] std.cfg: Add "buffer-size" attribute and tests for aligned_alloc(). --- cfg/std.cfg | 2 +- test/cfg/std.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index a655528c2..35dcb8796 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -7312,7 +7312,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun malloc calloc - aligned_alloc + aligned_alloc free diff --git a/test/cfg/std.c b/test/cfg/std.c index dd7819ea3..db43495e8 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -75,6 +75,12 @@ void bufferAccessOutOfBounds(void) fwrite(a,1,5,stdout); // cppcheck-suppress bufferAccessOutOfBounds fread(a,1,6,stdout); + + char * pAlloc1 = aligned_alloc(8, 16); + memset(pAlloc1, 0, 16); + // cppcheck-suppress bufferAccessOutOfBounds + memset(pAlloc1, 0, 17); + free(pAlloc1); } void bufferAccessOutOfBounds_libraryDirectionConfiguration(void) @@ -89,6 +95,15 @@ void bufferAccessOutOfBounds_libraryDirectionConfiguration(void) arr[c] = 'x'; } +void arrayIndexOutOfBounds() +{ + char * pAlloc1 = aligned_alloc(8, 16); + pAlloc1[15] = '\0'; + // cppcheck-suppress arrayIndexOutOfBounds + pAlloc1[16] = '1'; + free(pAlloc1); +} + // memory leak void ignoreleak(void)