std.cfg: Add "buffer-size" attribute and tests for aligned_alloc().

This commit is contained in:
versat 2019-03-21 09:25:42 +01:00
parent 55433fce40
commit 316475f79f
2 changed files with 16 additions and 1 deletions

View File

@ -7312,7 +7312,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<memory> <memory>
<alloc init="false" buffer-size="malloc">malloc</alloc> <alloc init="false" buffer-size="malloc">malloc</alloc>
<alloc init="true" buffer-size="calloc">calloc</alloc> <alloc init="true" buffer-size="calloc">calloc</alloc>
<alloc init="false">aligned_alloc</alloc> <alloc init="false" buffer-size="malloc:2">aligned_alloc</alloc>
<dealloc>free</dealloc> <dealloc>free</dealloc>
</memory> </memory>
<resource> <resource>

View File

@ -75,6 +75,12 @@ void bufferAccessOutOfBounds(void)
fwrite(a,1,5,stdout); fwrite(a,1,5,stdout);
// cppcheck-suppress bufferAccessOutOfBounds // cppcheck-suppress bufferAccessOutOfBounds
fread(a,1,6,stdout); 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) void bufferAccessOutOfBounds_libraryDirectionConfiguration(void)
@ -89,6 +95,15 @@ void bufferAccessOutOfBounds_libraryDirectionConfiguration(void)
arr[c] = 'x'; arr[c] = 'x';
} }
void arrayIndexOutOfBounds()
{
char * pAlloc1 = aligned_alloc(8, 16);
pAlloc1[15] = '\0';
// cppcheck-suppress arrayIndexOutOfBounds
pAlloc1[16] = '1';
free(pAlloc1);
}
// memory leak // memory leak
void ignoreleak(void) void ignoreleak(void)