
Initialise Structs, Arrays and Heap Buffers Safely in C
Initialize C structs, arrays and malloc buffers so Valgrind reports no uninitialised reads, including the padding bytes that surprise you when data is written.
Tag
255 posts

Initialize C structs, arrays and malloc buffers so Valgrind reports no uninitialised reads, including the padding bytes that surprise you when data is written.

Use arm_neon.h to write NEON vector loops in C for AArch64: float32x4_t, vld1q_f32, vaddq_f32, vfmaq_f32 and vaddvq_f32, with a full dot product and its output.

Select a pin's function with pinctrl-names and pinctrl-0, define groups in the SoC's pin controller node and check the result in debugfs.

Move slow work out of a Zephyr interrupt handler with k_work_submit and the system workqueue, with the work item rules, a GPIO example and sizing tips.

strerror_r has two incompatible signatures in glibc. Learn which one you get, how to write code that works with both, and how strerror_l avoids the problem.

Learn the Cortex-M vector table layout: system entries, device IRQs, the Thumb bit, how VTOR finds the table, and why it must sit at the start of flash.

How VMX and SVM add a guest mode to x86 processors, what the VMCS and VMCB hold, why VM exits happen and how nested paging removes shadow page tables.

Write and maintain a Valgrind suppression file with --gen-suppressions, wildcards and match-leak-kinds so known library noise stops hiding real bugs.

Convert a 128-bit SSE integer loop to 256-bit AVX2: new types, a step of eight, the -mavx2 flag, runtime dispatch and the lane-crossing trap.

Write a 64-bit RISC-V kernel in C and assembly for QEMU virt: boot through OpenSBI, traps, timer, paging with Sv39, a page allocator, tasks and user mode.

Use valgrind --track-origins=yes to find where an uninitialised value was created, so the Memcheck report points at the real bug and not just the branch.

Copy a float into a uint32_t with memcpy, then mask out the sign, exponent and fraction fields to see exactly how IEEE 754 stores it.