5.47 · exercise
The leaky frame
warning
This program is broken. Find the bug and fix it so the checks pass.
This program stashes a lucky number from input in its stack frame and prints it back. It should print one line. Run it: the program dies before printing anything, exactly the way it would crash with a bus error on the course servers.
The rule it breaks: sp must stay 16-byte aligned (a multiple of 16) whenever a function is called. Count the bytes this frame allocates and check them against the course's alignment formula, alloc = -(16 + locals) & -16. Fix the allocation and its matching deallocation so the frame is legal.
What is checked
- the lucky number is printed
- the program exits cleanly
- the value still makes its round trip through the frame (
strandldrintact) - the same holds for other numbers you do not see, and on those runs
mainmust also give back exactly the bytes it took and keep its local inside its own frame
specification
stdin7
stdoutprints the right output
exitexits with the right code
sourceuses
strsourceuses
ldrhiddenright output and exit code on 4 more inputs you do not see
We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.