Task: Memory Corruption
For this practice item, you will need to identify the programming mistake that makes it possible to corrupt memory.
Navigate to the labs/lab-03/tasks/memory-corruption/ folder, and enter support/src/. Inspect the source file segfault.c.
- What does the program do? (this could be a quiz in the final form)
- Compile and run it. What happens?
- Debug the program and find the line that causes the segfault. Note: Although using
printf()calls is a viable option, we strongly suggest you use GDB. - Fix the program and check your changes by running the
checker.shscript insupport/tests/. - Analyze the corresponding Python and D implementation.
What is the expected result in each case? Why? Run the programs and see what happens.
If you’re having difficulties solving this exercise, go through this reading material.