How to make it so that after executing return
go to any other part of the program instead of the function call point?
The answer can not even suggest: (
This is one of the crazy assignments for interviews, when they offer to make complete nonsense and write code for which you should take your hands off in life, instead of checking out the real knowledge of the candidate?
Alternatively, define return:
#include <stdio.h> #define return goto ll void main() { return; printf("You shouldn't see this\n"); ll: printf("After return\n"); }
Option two is to replace the return address by simulating a buffer overflow (talking about the call stack, I offer this example to students). Remarks: (1) it works only on 32 bits, (2) after the output of the string, the program will of course collapse. Both shortcomings are easy to fix, I suggest to do it yourself.
#include <stdio.h> void non_called_function() { printf("You shouldn't see this\n"); } void f() { int testArray[1]; // Замещаем адрес возврата в main адресом non_called_function testArray[2] = (int) non_called_function; } int main() { f(); return 0; }
-mpreferred-stack-boundary
switch, but I have not tried it. - northernerIf you want the transition to take place exactly by return, this is one thing. If just at the end of the function, then look towards long_jmp
. Although, in fact, I would deal with such things as a last resort.
And if you use an unconditional goto
transition?
Source: https://ru.stackoverflow.com/questions/101842/
All Articles