Skip to content

Commit

Permalink
Add memset/memcpy test case with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Sep 30, 2023
1 parent 87dadd2 commit 9e9b5e3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/regression/77-mem-oob/08-memset-memcpy-array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// PARAM: --set ana.activated[+] memOutOfBounds --enable ana.int.interval --disable warn.info
// TODO: The "--disable warn.info" part is a temporary fix and needs to be removed once the MacOS CI job is fixed
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[]) {
int arr[42]; // Size should be 168 bytes (with 4 byte ints)
int *b = arr;


memset(b, 0, 168); //NOWARN
memset(b, 0, sizeof(arr)); //NOWARN
memset(b, 0, 169); //WARN
memset(b, 0, sizeof(arr) + 1); //WARN

int *c = malloc(sizeof(arr)); // Size should be 168 bytes (with 4 byte ints)
memcpy(b, c, 168); //NOWARN
memcpy(b, c, sizeof(arr)); //NOWARN
memcpy(b, c, 169); //WARN
memcpy(b, c, sizeof(arr) + 1); //WARN

int d;

if (*argv == 42) {
b = &d;
memset(b, 0, 168); //WARN
memcpy(b, c, 168); //WARN
} else if (*(argv + 5)) {
int random = rand();
b = &random;
memset(b, 0, 168); //WARN
memcpy(b, c, 168); //WARN
}

memset(b, 0, sizeof(arr)); //WARN
memcpy(b, c, sizeof(arr)); //WARN
memset(b, 0, sizeof(int)); //NOWARN
memcpy(b, c, sizeof(int)); //NOWARN
memset(b, 0, sizeof(int) + 1); //WARN
memcpy(b, c, sizeof(int) + 1); //WARN

return 0;
}

0 comments on commit 9e9b5e3

Please sign in to comment.