@@ -15,21 +15,18 @@ template <class T> static constexpr T RoundDown(T x) {
15
15
~(kGranularity - 1 ));
16
16
}
17
17
18
- void TestContainer (size_t capacity, size_t off_begin, size_t off_end,
19
- bool poison_buffer) {
20
- char *buffer = new char [capacity + off_begin + off_end];
21
- char *buffer_end = buffer + capacity + off_begin + off_end;
18
+ void TestContainer (size_t capacity, size_t off_begin, bool poison_buffer) {
19
+ size_t buffer_size = capacity + off_begin + kGranularity * 2 ;
20
+ char *buffer = new char [buffer_size];
22
21
if (poison_buffer)
23
- __asan_poison_memory_region (buffer, buffer_end - buffer);
24
- else
25
- __asan_unpoison_memory_region (buffer, buffer_end - buffer);
22
+ __asan_poison_memory_region (buffer, buffer_size);
26
23
char *beg = buffer + off_begin;
27
24
char *end = beg + capacity;
28
25
char *mid = poison_buffer ? beg : beg + capacity;
29
26
char *old_mid = 0 ;
30
27
// If after the container, there is another object, last granule
31
28
// cannot be poisoned.
32
- char *cannot_poison = (off_end == 0 ) ? end : RoundDown (end);
29
+ char *cannot_poison = (poison_buffer ) ? end : RoundDown (end);
33
30
34
31
for (int i = 0 ; i < 1000 ; i++) {
35
32
size_t size = rand () % (capacity + 1 );
@@ -48,13 +45,13 @@ void TestContainer(size_t capacity, size_t off_begin, size_t off_end,
48
45
assert (!__asan_address_is_poisoned (beg + idx));
49
46
for (size_t idx = size; beg + idx < cannot_poison; idx++)
50
47
assert (__asan_address_is_poisoned (beg + idx));
51
- for (size_t idx = 0 ; idx < off_end ; idx++)
48
+ for (size_t idx = 0 ; idx < kGranularity ; idx++)
52
49
assert (__asan_address_is_poisoned (end + idx) == poison_buffer);
53
50
54
51
assert (__sanitizer_verify_contiguous_container (beg, mid, end));
55
52
assert (NULL ==
56
53
__sanitizer_contiguous_container_find_bad_address (beg, mid, end));
57
- size_t distance = (off_end > 0 ) ? kGranularity + 1 : 1 ;
54
+ size_t distance = (end > RoundDown (end) ) ? kGranularity + 1 : 1 ;
58
55
if (mid >= beg + distance) {
59
56
assert (
60
57
!__sanitizer_verify_contiguous_container (beg, mid - distance, end));
@@ -71,7 +68,7 @@ void TestContainer(size_t capacity, size_t off_begin, size_t off_end,
71
68
}
72
69
}
73
70
74
- __asan_unpoison_memory_region (buffer, buffer_end - buffer );
71
+ __asan_unpoison_memory_region (buffer, buffer_size );
75
72
delete[] buffer;
76
73
}
77
74
@@ -100,9 +97,8 @@ void TestThrow() {
100
97
int main (int argc, char **argv) {
101
98
int n = argc == 1 ? 64 : atoi (argv[1 ]);
102
99
for (int i = 0 ; i <= n; i++)
103
- for (int j = 0 ; j < 8 ; j++)
104
- for (int k = 0 ; k < 8 ; k++)
105
- for (int poison = 0 ; poison < 2 ; ++poison)
106
- TestContainer (i, j, k, poison);
100
+ for (int j = 0 ; j < kGranularity * 2 ; j++)
101
+ for (int poison = 0 ; poison < 2 ; ++poison)
102
+ TestContainer (i, j, poison);
107
103
TestThrow ();
108
104
}
0 commit comments