From the course: Debugging C Code
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Fix the code - C Tutorial
From the course: Debugging C Code
Solution: Fix the code
(upbeat music) - [Instructor] I fired up the GNU debugger and loaded the program for this challenges exercise file. The buffers are filled with periods starting at line 12. The second loop at line 25 copies the strings, but what I'm curious about is the duplicate buffer and how it gets so crazy. Set a break point after the string is copied at line 29. Run the program, fill in your name and the break point is encountered. Now let's look at some values first, the original buffer and the duplicate. Do you see the problem? The null character is missing from the string. See how it appears in the original string, but it's not copied to the duplicate. This command dumps memory in the running program to file.dat from the address at duplicate to the address at duplicate plus 48 bytes. Shell out to the hex dump utility to view the file. The dump explains a lot. You see the duplicated string, but also the buffer filled with periods. Then at the 32nd bite, you see what I'm guessing is the…