-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memset/memcpy test case with arrays
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |