Skip to content

Commit 0081ba6

Browse files
committed
fix(spill): declare the parked result image defined to Valgrind Memcheck
The result spill writes each parked result as an opaque image: the record header (a struct copy) and the compacted arena block. Both contain struct padding that no code writes, and the image is read back whole, never interpreted byte by byte. MemorySanitizer builds already declare the image defined before the fwrite. Valgrind Memcheck flags the same bytes at write(2) ("Syscall param write(buf) points to uninitialised byte(s)"), with origins in stack-built records such as CBMReadWrite in handle_readwrites and the import record in py_ns_import. Zeroing those records one at a time only moves the report to the next record type. When <valgrind/memcheck.h> is available (non-Windows, __has_include), SPILL_IMAGE_DEFINED now issues VALGRIND_MAKE_MEM_DEFINED. Outside Valgrind that is a few no-op instructions. Builds without the header compile it to nothing as before. Verified: extraction:extract_spill_round_trip_keeps_every_field under Memcheck went from 1 error context to 0. The extraction suite passes (470), and the -Werror build and lint pass.
1 parent 3dada7c commit 0081ba6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎internal/cbm/result_spill.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
2929
* image that is read back whole and never interpreted byte by byte (CI MSan
3030
* lane on #2202: offset 4087, then 6714, of a 6,952-byte block). Under MSan
3131
* the image is declared defined right before the write; every other build
32-
* compiles this to nothing. */
32+
* compiles this to nothing. Valgrind Memcheck flags the same padding at the
33+
* write(2), so when its client-request header is available the image is
34+
* declared defined to it too (a few no-op instructions outside Valgrind). */
3335
#include "foundation/sanitized.h" /* __has_feature exists everywhere, cppcheck included */
3436
#if __has_feature(memory_sanitizer)
3537
#include <sanitizer/msan_interface.h>
3638
#define SPILL_IMAGE_DEFINED(p, n) __msan_unpoison((p), (n))
39+
#elif !defined(_WIN32) && defined(__has_include)
40+
#if __has_include(<valgrind/memcheck.h>)
41+
#include <valgrind/memcheck.h>
42+
#define SPILL_IMAGE_DEFINED(p, n) ((void)VALGRIND_MAKE_MEM_DEFINED((p), (n)))
43+
#else
44+
#define SPILL_IMAGE_DEFINED(p, n) ((void)0)
45+
#endif
3746
#else
3847
#define SPILL_IMAGE_DEFINED(p, n) ((void)0)
3948
#endif

0 commit comments

Comments
 (0)