...
Because g()
has finished executing at the time longjmp()
is called, it is no longer on the stack. When do_stuff()
is invoked, its stack frame occupies the same memory as the old stack frame of g()
. In this case, a
was located in the same location as the return address of function g()
. The call to memcpy()
assignment of b
overwrites the return address, so when longjmp()
sends control back to function g()
, the function returns to the wrong address (in this case, to function bad()
).
...