| 13 | |
| 14 | #define GUARDSIZE 32 |
| 15 | void test_memset(int copySize, int offset) { |
| 16 | char *content = ptr + GUARDSIZE + offset; |
| 17 | |
| 18 | char *guardBefore = content - GUARDSIZE; |
| 19 | char *guardAfter = content + copySize; |
| 20 | |
| 21 | char guard = (char)rand(); |
| 22 | |
| 23 | for (int i = 0; i < GUARDSIZE; ++i) { |
| 24 | // Generate a guardband area around memory that should not change. |
| 25 | guardBefore[i] = (char)(guard ^ i); |
| 26 | guardAfter[i] = (char)(guard ^ i); |
| 27 | } |
| 28 | |
| 29 | // Generate fill source data |
| 30 | char s = (char)(rand() ^ 0xF0); |
| 31 | |
| 32 | memset(content, s, copySize); |
| 33 | for (int i = 0; i < copySize; ++i) { |
| 34 | if (content[i] != s) { |
| 35 | printf("test_memset(copySize=%d, offset=%d failed!\n", copySize, offset); |
| 36 | exit(1); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Verify guardband area |
| 41 | for (int i = 0; i < GUARDSIZE; ++i) { |
| 42 | // Generate a guardband area around memory that should not change. |
| 43 | if (guardBefore[i] != (char)(guard ^ i)) { |
| 44 | printf("test_memset(copySize=%d, offset=%d failed! Pre-guardband area at i=%d overwritten!\n", copySize, offset, i); |
| 45 | exit(1); |
| 46 | } |
| 47 | if (guardAfter[i] != (char)(guard ^ i)) { |
| 48 | printf("test_memset(copySize=%d, offset=%d failed! Post-guardband area at i=%d overwritten!\n", copySize, offset, i); |
| 49 | exit(1); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void test_copysize(int copySize) { |
| 55 | for (int offset = 0; offset < 31; ++offset) { |
no test coverage detected