(fix commit c058d9d)
The data race has not affected the functionality of the test but this
commit allows to avoid no_sanitize attribute for the function.
* tests/test_malloc.c (cons): Remove AO_ATTR_NO_SANITIZE_THREAD
attribute; Do not reset extra (use "%" operator to get my_extra value).
* tests/test_malloc.c [AO_HAVE_fetch_and_add1] (cons): Change type of
extra to AO_t, add volatile qualifier; use AO_fetch_and_add1 instead of
"++" operator to update extra.
int data;
} ln;
-AO_ATTR_NO_SANITIZE_THREAD
ln *cons(int d, ln *tail)
{
- static size_t extra = 0; /* data race in extra is OK */
- size_t my_extra = extra;
+# ifdef AO_HAVE_fetch_and_add1
+ static volatile AO_t extra = 0;
+ size_t my_extra = (size_t)AO_fetch_and_add1(&extra) % 101;
+# else
+ static size_t extra = 0; /* data race in extra is OK */
+ size_t my_extra = (extra++) % 101;
+# endif
ln *result;
int * extras;
unsigned i;
- if (my_extra > 100)
- extra = my_extra = 0;
- else
- ++extra;
result = AO_malloc(sizeof(ln) + sizeof(int)*my_extra);
if (result == 0)
{