here is the c code:
char **s;
s[334]=strdup("test");
printf("%s\n",s[334]);`
i know that strdup does the allocation of “test”, but the case s[334] where we will put the pointer to the string “test” is not allocated,however,this code works like a charm
The compiler is too smart for us! It knows that
printf("%s\n", some_string)is exactly the same asputs(some_string), so it can simplifyinto
and then (assuming no UB) that is again equivalent to
So, by chance the segment fault didn’t happen (this time).