Skip to content

Posts

C Basics: Move Overlapping Text Within One Buffer

Use memmove for overlapping ranges and include the string terminator when shifting text.

Read more →

November 1, 2026

C Basics: Make Configuration Fields Explicit with Designated Initializers

Initialize a configuration by field name and represent its state with an enum.

Read more →

November 1, 2026

C Basics: Keep Byte Input Separate from EOF

Store fgetc results in int so byte values cannot be confused with the EOF sentinel.

Read more →

November 1, 2026

C Basics: Grow an Allocation Without Losing Its Owner

Keep the original pointer until realloc succeeds and check allocation-size multiplication.

Read more →

November 1, 2026

C Basics: Find a Record in a Sorted Array with bsearch

Search a table by numeric key while preserving the ordering contract required by bsearch.

Read more →

November 1, 2026

C Basics: Encode a 32-Bit Value with Explicit Byte Order

Write and read four big-endian octets without casting byte buffers to integer pointers.

Read more →

November 1, 2026

C Basics: Distinguish a Short Binary Read from an Error

Read binary bytes with fread and inspect EOF and error indicators after a short read.

Read more →

November 1, 2026

C Basics: Detect Truncated Formatting with snprintf

Check the required length before accepting a bounded formatted string.

Read more →

November 1, 2026

C Basics: Check Multiplication Before Allocating an Array

Reject overflowing allocation-size calculations and handle allocation failure separately.

Read more →

November 1, 2026

C Basics: Check Fixed Buffer Relationships at Compile Time

Use _Static_assert to reject inconsistent constant sizes before a program can run.

Read more →

November 1, 2026