aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-52.c
blob: a28965557c3de83a63194f50c4dff3b7ec95802b (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

/* PR middle-end/97023 - missing warning on buffer overflow in chained mempcpy
   Verify that writes by built-in functions to objects through pointers
   returned by ordinary (non-built-int) function are assumed to point to
   the beginning of objects.
   { dg-do compile }
   { dg-options "-O2" } */

#include "range.h"

void* memcpy (void*, const void*, size_t);
void* memset (void*, int, size_t);

void sink (void*, ...);

extern char* arrptr[];
extern char* ptr;
extern char* retptr (void);
struct S { char *p; };
extern struct S retstruct (void);

void nowarn_ptr (void)
{
  {
    void *p = arrptr;
    memset (p - 1, 0, 12345);           // { dg-warning "\\\[-Wstringop-overflow" }
    memset (p,0, 12345);
    memset (p,0, DIFF_MAX - 1);
  }

  {
    char *p = arrptr[0];
    memset (p - 1, 0, 12345);
    memset (p - 12345, 0, 12345);
    memset (p - 1234, 0, DIFF_MAX - 1);
    memset (p - DIFF_MAX + 1, 0, 12345);
  }

  {
    char *p = ptr;
    memset (p - 1, 0, 12345);
    memset (p - 12345, 0, 12345);
    memset (p - 1234, 0, DIFF_MAX - 1);
    memset (p - DIFF_MAX + 1, 0, 12345);
  }

  {
    char *p = retptr ();
    memset (p - 1, 0, 12345);
    memset (p - 12345, 0, 12345);
    memset (p - 1234, 0, DIFF_MAX - 1);
    memset (p - DIFF_MAX + 1, 0, 12345);
  }

  {
    char *p = retstruct ().p;
    memset (p - 1, 0, 12345);
    memset (p - 12345, 0, 12345);
    memset (p - 1234, 0, DIFF_MAX - 1);
    memset (p - DIFF_MAX + 1, 0, 12345);
  }
}