summaryrefslogtreecommitdiff
path: root/src/debug_smoke_test.sh
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2026-10-15 16:26:43 -0700
committerScott Gasch <[email protected]>2026-10-15 16:26:43 -0700
commitc179ae5ad9f1a0efb68904033621705fd060aea4 (patch)
tree2f0639b4699a7825b6983f27518497d388eb0e2d /src/debug_smoke_test.sh
parent1ea81bae240912efb8cebabae35fe58bc5d12afb (diff)
Fix overlapping-buffer sprintf/snprintf bugs in fen.c and gamelist.c
Both FenFromPosition and the status-line builder in gamelist.c were reading and writing the same buffer within a single sprintf/snprintf call (e.g. sprintf(pHeap, "%s...", pHeap, ...)) -- undefined behavior per the C standard since the source and destination overlap, caught by valgrind as uninitialised-value reads even though no DEBUG ASSERT ever tripped. Fixed by building each piece into a separate buffer (or appending via snprintf/strncat into the already-terminated prefix) instead of re-reading the destination as a source argument. debug_smoke_test.sh: added a valgrind pass over the same sampled smoke-test positions, since this class of bug produces no ASSERT failure and was otherwise invisible to the existing smoke test. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Diffstat (limited to 'src/debug_smoke_test.sh')
-rwxr-xr-xsrc/debug_smoke_test.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/debug_smoke_test.sh b/src/debug_smoke_test.sh
index d8ef228..f1ce4e4 100755
--- a/src/debug_smoke_test.sh
+++ b/src/debug_smoke_test.sh
@@ -80,3 +80,29 @@ if [ "$STATUS" -ne 0 ]; then
exit 1
fi
echo "SMOKE TEST PASSED"
+
+# Valgrind pass: catches memory errors (e.g. overlapping-buffer sprintf/
+# memcpy, invalid reads/writes) that don't trip a DEBUG ASSERT but are
+# still real bugs. Reuses the same sampled positions. --cpus 1 because
+# valgrind + MP threading is slow and noisy for no real benefit here --
+# this is checking memory safety, not search behavior. error-exitcode=99
+# distinguishes "valgrind found a problem" from a normal engine exit.
+if command -v valgrind >/dev/null 2>&1; then
+ VGLOG="$LOGDIR/valgrind_${STAMP}.log"
+ VGOUT="$LOGDIR/valgrind_${STAMP}.out"
+ echo "=== valgrind pass over the same $COUNT positions ==="
+ valgrind -s --leak-check=full --error-exitcode=99 --log-file="$VGLOG" \
+ "$BIN" --cpus 1 --hash 64m --logfile /dev/null \
+ --batch --command "force; book name /nonexistent.book.bin; sd $DEPTH; script $SAMPLE" \
+ > "$VGOUT" 2>&1
+ VGSTATUS=$?
+ if [ "$VGSTATUS" -eq 99 ]; then
+ echo " *** VALGRIND ERRORS DETECTED -- see $VGLOG ***"
+ echo "SMOKE TEST FAILED"
+ exit 1
+ fi
+ echo " valgrind: clean (see $VGLOG)"
+else
+ echo " (valgrind not found on PATH, skipping memory-error pass)"
+fi
+echo "SMOKE TEST PASSED"