This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

unnoticed invalid dereference when using address sanitizer


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]