unnoticed invalid dereference when using address sanitizer

Warlich, Christof christof.warlich@siemens.com
Fri Apr 1 15:02:00 GMT 2016


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,


#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;
    printf("%d\n", f(*psimple));

    int *pint = (int *) malloc(sizeof(int));
    *pint = 24;
    printf("%d\n", g(*pint));

    return 0;

More information about the Gcc-help mailing list