在 6/23/21 6:32 PM, Erick Ochoa via Gcc 写道:
I notice that in these special cases, the printf function is nowhere to be found, and if one prints a pointer using printf the pointer points to escaped memory. Why is this the case?
I think it is due to the incapability of ruling out the possibility of code that attempts to read the pointer back and modifies the pointee, like follows:
```c #include <stdio.h> int main(void) { static char buf[200]; setvbuf(stdout, buf, _IOFBF, sizeof(buf)); int value = 42; printf("%p\n", (void*)&value); void* ptr = 0; if(sscanf(buf, "%p", &ptr)) *(int*)ptr = 100; fprintf(stderr, "value = %d\n", value); // 100 instead of 42 } ``` -- Best regards, Liu Hao
OpenPGP_signature
Description: OpenPGP digital signature