blob: 9dabc7ee277f135ecd0056f2ff33bec25604555f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* { dg-do compile } */
/* { dg-options "-Wall -O3" } */
typedef long unsigned int size_t;
inline void
fill (int *p, size_t n, int)
{
while (n--)
*p++ = 0;
}
struct B
{
int* p0, *p1, *p2;
size_t size () const {
return size_t (p1 - p0);
}
void resize (size_t n) {
if (n > size())
append (n - size());
}
void append (size_t n)
{
if (size_t (p2 - p1) >= n) {
fill (p1, n, 0);
}
}
};
void foo (B &b)
{
b.resize (b.size () - 1);
}
/* If b.size() == 0, then the argument to b.resize is -1U (it overflowed).
This will result calling "fill" which turns into a memset with a bogus
length argument. We want to make sure we warn, which multiple
things. First the ldist pass converted the loop into a memset,
cprop and simplifications made the length a constant and the static
analysis pass determines it's a bogus size to pass to memset. */
/* { dg-warning "exceeds maximum object size" "" { target *-*-* } 0 } */
|