(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
out-of-bounds-write-int-arr.c
       1  #include <stdint.h>
       2  
       3  int32_t arr[10]; /* { dg-message "capacity: 40 bytes" } */
       4  
       5  void int_arr_write_element_before_start_far(int32_t x)
       6  {
       7    arr[-100] = x; /* { dg-warning "buffer underwrite" "warning" } */
       8    /* { dg-message "out-of-bounds write from byte -400 till byte -397 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
       9    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
      10  }
      11  
      12  void int_arr_write_element_before_start_near(int32_t x)
      13  {
      14    arr[-2] = x; /* { dg-warning "buffer underwrite" "warning" } */
      15    /* { dg-message "out-of-bounds write from byte -8 till byte -5 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
      16    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
      17  }
      18  
      19  void int_arr_write_element_before_start_off_by_one(int32_t x)
      20  {
      21    arr[-1] = x; /* { dg-warning "buffer underwrite" "warning" } */
      22    /* { dg-message "out-of-bounds write from byte -4 till byte -1 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
      23    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
      24  }
      25  
      26  void int_arr_write_element_at_start(int32_t x)
      27  {
      28    arr[0] = x;
      29  }
      30  
      31  void int_arr_write_element_at_end(int32_t x)
      32  {
      33    arr[9] = x;
      34  }
      35  
      36  void int_arr_write_element_after_end_off_by_one(int32_t x)
      37  {
      38    arr[10] = x; /* { dg-warning "buffer overflow" "warning" } */
      39    /* { dg-message "out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
      40    /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
      41    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */
      42  }
      43  
      44  void int_arr_write_element_after_end_near(int32_t x)
      45  {
      46    arr[11] = x; /* { dg-warning "buffer overflow" "warning" } */
      47    /* { dg-message "out-of-bounds write from byte 44 till byte 47 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
      48    /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
      49    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */
      50  }
      51  
      52  void int_arr_write_element_after_end_far(int32_t x)
      53  {
      54    arr[100] = x; /* { dg-warning "buffer overflow" "warning" } */
      55    /* { dg-message "out-of-bounds write from byte 400 till byte 403 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
      56    /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
      57    /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */
      58  }