Skip to content

Instantly share code, notes, and snippets.

@steipete
Created November 1, 2012 15:38
Show Gist options
  • Save steipete/3994427 to your computer and use it in GitHub Desktop.
Save steipete/3994427 to your computer and use it in GitHub Desktop.
* 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