#include <stdio.h>
void CauseUB(int a, int **b) {
*b = &a;
}
int main() {
int x = 5, *y = &x;
printf("This is OK: %d\n", *y
); CauseUB(x, &y); // Pointer to pointer
printf("Make sure stuff gets placed on the stack... %d\n", 2*x
+13); printf("This is UB: %d\n", *y
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIENhdXNlVUIoaW50IGEsIGludCAqKmIpIHsKICAgICpiID0gJmE7Cn0KaW50IG1haW4oKSB7CiAgICBpbnQgeCA9IDUsICp5ID0gJng7CiAgICBwcmludGYoIlRoaXMgaXMgT0s6ICVkXG4iLCAqeSk7CiAgICBDYXVzZVVCKHgsICZ5KTsgLy8gUG9pbnRlciB0byBwb2ludGVyCiAgICBwcmludGYoIk1ha2Ugc3VyZSBzdHVmZiBnZXRzIHBsYWNlZCBvbiB0aGUgc3RhY2suLi4gJWRcbiIsIDIqeCsxMyk7CiAgICBwcmludGYoIlRoaXMgaXMgVUI6ICVkXG4iLCAqeSk7CiAgICByZXR1cm4gMDsKfQoK