1  /* { dg-do run } */
       2  /* { dg-options "-fno-builtin-malloc -fno-builtin-free -fno-builtin-memset" } */
       3  /* { dg-shouldfail "asan" } */
       4  
       5  #ifdef __cplusplus
       6  extern "C" {
       7  #endif
       8  
       9  void *memset (void *, int, __SIZE_TYPE__);
      10  void *malloc (__SIZE_TYPE__);
      11  void free (void *);
      12  
      13  #ifdef __cplusplus
      14  }
      15  #endif
      16  
      17  volatile int ten = 10;
      18  int main(int argc, char **argv) {
      19    char *x = (char*)malloc(10);
      20    memset(x, 0, 10);
      21    int res = x[ten];  /* BOOOM */
      22    free(x);
      23    return res;
      24  }
      25  
      26  /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
      27  /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:21|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */
      28  /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes after 10-byte region\[^\n\r]*(\n|\r\n|\r)" } */
      29  /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
      30  /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
      31  /* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:19|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */