Hi Folks ,
Wondering if someone can explain this
Adress sanitizer does not report and leak in this code below when compiled
with O1 , O2 ,,,
But it works as expected when compiled with O0
#include <stdio.h>
#include <stdlib.h>
int main () {
volatile char *str;
/* Initial memory allocation */
str = (char *) malloc(25);
strcpy(str, "sameple st");
printf("String = %s, Address = %u\n", str, str);
strcat(str, "append");
printf("String = %s, Address = %u\n", str, str);
return(0);
}
I am compiling this code as
gcc -fsanitize=address -O0 a.c
gcc --version
gcc (GCC) 8.2.1 20190102
I looked at asm code also and clearly malloc has not been removed by
optimizers
22 .cfi_startproc
23 pushq %rbp
24 .cfi_def_cfa_offset 16
25 .cfi_offset 6, -16
26 movq %rsp, %rbp
27 .cfi_def_cfa_register 6
28 subq $16, %rsp
29 movl $25, %edi
30 *call malloc*
31 movq %rax, -8(%rbp)
32 movq -8(%rbp), %rax
33 movl $11, %edx
34 movl $.LC0, %esi
35 movq %rax, %rdi
36 call memcpy
Any clue what is happening here ?
--
You received this message because you are subscribed to the Google Groups
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.