https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105592
Bug ID: 105592
Summary: array out of bound not detected by ubsan
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at
gcc dot gnu.org
Target Milestone: ---
Hi,
For the following code, I wonder why &a[1] is not considered as an out-of-bound
while &a[2] is.
$cat a1.c
a[1];
main() {
int *b = &a[1];
return *b;
}
$
$gcc -O0 -fsanitize=bounds -w a1.c && ./a.out
$
$ cat a2.c
a[1];
main() {
int *b = &a[2];
return *b;
}
$gcc -O0 -fsanitize=bounds -w a2.c && ./a.out
a2.c:3:14: runtime error: index 2 out of bounds for type 'int [1]'
$