Skip to content
Courses

Code Investigation Lab

Programming FoundationsLab 3 of 3 · Investigative90–120 minutesLabBuilds on: Reading Unfamiliar Code

Finish every Programming Foundations lesson and both of the earlier programming labs before you start. Work in the Ubuntu 24.04.4 LTS x86-64 course VM, with GCC 13.x.

The supplied source is the entire target here. Keep it unchanged until the modification milestone, and work only on a copy once you get that far (the original is your reference). This lab is assessing source reading and controlled testing (not speed, and not tooling).

Download code-investigation-v2.0.0.tar to ~/underdunn-course/downloads.

Terminal window
cd ~/underdunn-course/downloads
sha256sum code-investigation-v2.0.0.tar

Expected digest:

075c2d628928ce15487b2ba00eec3927a3c5a5ff184bb1f5d92fd54649ca3a95 code-investigation-v2.0.0.tar

Extract and verify the internal source identity:

Terminal window
mkdir -p ~/underdunn-course/labs/code-investigation
tar -xf code-investigation-v2.0.0.tar -C ~/underdunn-course/labs/code-investigation
cd ~/underdunn-course/labs/code-investigation/code-investigation-v2.0.0
sha256sum -c CHECKSUMS.sha256

Before you run anything, I’d build a map of the program from the source alone, using the same read-before-you-run habit from the last lesson. Read investigate.c and find:

  • Constant and its value.
  • Enum states.
  • Structure fields.
  • Functions and their argument/return contracts.
  • Data array and element count expression.
  • Call graph beginning at main.

But don’t run the program yet, however tempting it looks by now.

Follow each supplied record through the deciding condition. You can use a scratch table if it helps.

Then predict all three summary counts. And treat the value sitting exactly on INSPECT_THRESHOLD as a boundary case in its own right, because it distinguishes >= from >.

Terminal window
gcc -std=c11 -Wall -Wextra -Wpedantic -O0 -g investigate.c -o investigate
./investigate
printf 'status=%s\n' "$?"

The build should emit no warnings at all, and the status should come back as zero. Compare the printed classifications with the conditions you followed. If one of them differs, find the first source condition where your trace diverged, and do it before you change anything.

Copy the source and change only INSPECT_THRESHOLD from 10 to 13:

Terminal window
cp investigate.c investigate-threshold-13.c

Predict which records and which summary counts are going to change, and then build and run the copy:

Terminal window
gcc -std=c11 -Wall -Wextra -Wpedantic -O0 -g \
investigate-threshold-13.c -o investigate-threshold-13
./investigate-threshold-13
diff -u investigate.c investigate-threshold-13.c

That diff has to show the threshold constant and nothing else at all. Check the changed rows, and then explain why the invalid record comes through completely unaffected.

Enter the original program’s summary counts: the number of records that ended up in each state. Use decimal values.

Check your answers

Enter the values you found. Your answers are checked in this browser without being sent anywhere.

The checker uses the baseline counts. Comparing the changed threshold shows which classifications depend on that boundary.

Hint 1: begin with the dataFind the four records and the threshold before following any function calls.
Hint 2: trace the boundaryclassify tests negative first, then uses >=. A value equal to the threshold enters the inspect state.
Hint 3: verify the summaryCount one enum result per record, then compare those counts with the indexes used in the final printf.
  • The archive or internal checksum doesn’t match: delete the affected copy, download or extract it again, and reverify before going further.
  • A compiler warning appears: restore the exact baseline and build that, before you reapply a single change.
  • You edited a prediction after running: restore the original entry from your notes, and add the revision separately underneath it.
  • Several source lines changed at once: discard that copy, copy the baseline again, and edit only the threshold this time.
  • A stale binary keeps running: rebuild the named output, and check its timestamp with ls -l.

The checker should accept the baseline counts. In the changed build, records that met the old threshold but fall below the new one should become watch. The invalid record should stay invalid. If the results differ, check the threshold constant you changed.

To retry the lab, remove only the extracted copy and keep the verified archive, so you don’t have to download and re-verify the whole thing again:

Terminal window
cd ~/underdunn-course/labs/code-investigation
rm -rf code-investigation-v2.0.0

Then extract a fresh copy from the archive you already have. When you’re finished for good, remove that archive too:

Terminal window
rm -f ~/underdunn-course/downloads/code-investigation-v2.0.0.tar