The previous example wasn't reliably demonstrating the danger of missing
null terminators because the stack happened to contain a '\0' byte
immediately after the array, making the broken code appear to work.
Added memset() to fill the stack with non-zero values before declaring
the unterminated array. This ensures the broken example actually exhibits
undefined behavior by reading past the array boundary, making the lesson
about null terminators clear and visible.
Changes:
- Added garbage array filled with 'Z' characters using memset()
- This forces printf() to read past the broken array until finding '\0'
- Readers now see actual garbage output demonstrating why null
terminators are required in C strings
Updated all git clone commands for the FreeBSD source repository to
explicitly checkout the releng/14.3 branch. This ensures readers are
working with FreeBSD 14.3 Release source code, which matches the
version used throughout the book examples.
Changed from:
git clone https://git.freebsd.org/src.git /usr/src
To:
git clone -b releng/14.3 https://git.freebsd.org/src.git /usr/src
This prevents confusion from version mismatches and ensures all kernel
module examples compile and function as documented.
The count variable was not being updated because the while loops were
running in subshells created by the pipe operator. Variable assignments
in subshells don't affect the parent shell, causing count to remain 0.
Changes:
- list_files.sh: Changed from pipe to here-document with command
substitution to keep the while loop in the main shell
- list_files_bash.sh: Changed from pipe to process substitution using
< <(...) syntax to avoid subshell creation for the while loop
Both scripts now correctly display the total number of files found.
THis fix make the script fully POSIX-compliant for FreeBSD /bin/sh
Replace bash-specific `read -d ''` with tmpfile approach.
The -d option is not available in POSIX sh, causing the script
to fail on FreeBSD systems.
- Use tmpfile=$(mktemp) instead of null-delimited pipe
- Add trap for cleanup
- Remove -print0 and read -d '' options
- Add empty filename safety check
Fixes: read: Illegal option -d
Adds the full draft of Chapter 6. This chapter has had only a single
review so far; readers should expect further edits and refinements
before the final book release.
Known issue:
- In the generated PDF, some code blocks appear before the section
titles they belong to. This seems to be a Pandoc rendering quirk.
I’ll investigate and fix later; for now, treat the Markdown as the
source of truth.
No functional changes to earlier chapters.