Created
November 1, 2012 15:38
-
-
Save steipete/3994427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* if (x) { | |
* block = ^{ printf("true\n"); }; | |
* } else { | |
* block = ^{ printf("false\n"); }; | |
* } | |
* block(); // unsafe!!! | |
* | |
* What is happening behind the scenes: | |
* | |
* if (x) { | |
* struct Block __tmp_1 = ...; // setup details | |
* block = &__tmp_1; | |
* } else { | |
* struct Block __tmp_2 = ...; // setup details | |
* block = &__tmp_2; | |
* } | |
* | |
* As the example demonstrates, the address of a stack variable is escaping the | |
* scope in which it is allocated. That is a classic C bug. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment