diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-02-17 22:07:15 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-02-17 22:07:15 +0300 |
commit | 6d3ad32c4c12607bce64a3d2fd2dc188acd423bb (patch) | |
tree | 59ee5efa842708802b9648e736db3588fcf8e158 | |
parent | 32d899e47fdf34655453f03e85183978feea88b0 (diff) | |
download | libatomic_ops-6d3ad32c4c12607bce64a3d2fd2dc188acd423bb.tar.gz |
Avoid breaking strict-aliasing rules in cons() of test_malloc
* tests/test_malloc.c (cons): Change type of extras local variable from
int* to char*; set every sizeof(int) byte of extras[] to 42 (instead of
setting every int value).
-rw-r--r-- | tests/test_malloc.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/test_malloc.c b/tests/test_malloc.c index 7888ba8..45a8c2c 100644 --- a/tests/test_malloc.c +++ b/tests/test_malloc.c @@ -78,7 +78,7 @@ ln *cons(int d, ln *tail) size_t my_extra = (extra++) % 101; # endif ln *result; - int * extras; + char *extras; unsigned i; result = (ln *)AO_malloc(sizeof(ln) + sizeof(int)*my_extra); @@ -91,8 +91,9 @@ ln *cons(int d, ln *tail) result -> data = d; result -> next = tail; - extras = (int *)(result+1); - for (i = 0; i < my_extra; ++i) extras[i] = 42; + extras = (char *)(result+1); + for (i = 0; i < my_extra; ++i) + extras[i*sizeof(int)] = 42; return result; } |