This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
unnoticed invalid dereference when using address sanitizer
- From: "Warlich, Christof" <christof dot warlich at siemens dot com>
- To: "gcc-help (gcc-help at gcc dot gnu dot org)" <gcc-help at gcc dot gnu dot org>
- Date: Fri, 1 Apr 2016 15:02:32 +0000
- Subject: unnoticed invalid dereference when using address sanitizer
- Authentication-results: sourceware.org; auth=none
Hi,
the code below has been compiled with GCC 5.3:
$ gcc -fsanitize=3Daddress -fno-omit-frame-pointer -g sanitize.c
When executing the result, the sanitizer only complains about the
invalid dereference of the second printf statement, while the first
one is executed unnoticed.
Did I encounter a gcc bug in the address sanitizer, or is this intended
behavior? If it is a bug, is there a related bug report already?
Thanks for any help,
Chris
#include <stdlib.h>
#include <stdio.h>
struct Simple {
int value;
};
int f(struct Simple simple) {
return simple.value;
}
int g(int value) {
return value;
}
int main() {
struct Simple *psimple = (struct Simple *) malloc(sizeof(struct Simple));
psimple->value = 42;
free(psimple);
printf("%d\n", f(*psimple));
int *pint = (int *) malloc(sizeof(int));
*pint = 24;
free(pint);
printf("%d\n", g(*pint));
return 0;
}