diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-07-20 21:59:39 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-07-21 20:33:52 +0300 |
commit | 4030df2387230e2fddf3e106c628293bc361ff46 (patch) | |
tree | 52bd36e02ed6b9388aa5c7e00e14df5382cbe05d | |
parent | 44b2f617bcfab287baa7703d1fe670d98561c41e (diff) | |
download | bdwgc-4030df2387230e2fddf3e106c628293bc361ff46.tar.gz |
Avoid gcc stringop-overflow warning for intended overflow in smashtest
* tests/smash_test.c (q): New global variable (volatile).
* tests/smash_test.c (main): Clear q if i is 3000 or 6000; set q to
the address of the modified byte if i is 5678; add comment.
-rw-r--r-- | tests/smash_test.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/smash_test.c b/tests/smash_test.c index 4ba7be04..9aab02de 100644 --- a/tests/smash_test.c +++ b/tests/smash_test.c @@ -13,6 +13,8 @@ char * A[COUNT]; +char * volatile q; + int main(void) { int i; @@ -23,8 +25,17 @@ int main(void) for (i = 0; i < COUNT; ++i) { A[i] = p = (char*)GC_MALLOC(SIZE); - if (i%3000 == 0) GC_gcollect(); - if (i%5678 == 0 && p != 0) p[SIZE + i/2000] = 42; + if (i%3000 == 0) { + q = NULL; + GC_gcollect(); + } else if (i%5678 == 0 && p != 0) { + /* Write a byte past the end of the allocated object */ + /* but not beyond the last word of the object's memory. */ + /* A volatile intermediate pointer variable is used to */ + /* avoid a compiler complain of out-of-bounds access. */ + q = &p[(SIZE + i/2000) /* 42 */]; + *q = 42; + } } return 0; } |