From a4162b6086586954dbc65e452518a4355c48a253 Mon Sep 17 00:00:00 2001 From: Ganesh Patil <7030871503ganeshpatil@gmail.com> Date: Tue, 24 Feb 2026 09:36:23 +0530 Subject: [PATCH] fix: clamp lag parameter to buffer size with warning (fixes #379) The circular buffer in plotymlag.py has a fixed size of 10. When a user sets lag >= size via tryparam, the modulo arithmetic silently wraps, producing incorrect data (e.g., lag=15 behaves like lag=5). Add input validation that clamps lag to size-1 and emits a logging.warning when the requested value exceeds the buffer capacity. This prevents silent data corruption while preserving backward compatibility and the existing circular buffer logic. --- tools/plotymlag.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/plotymlag.py b/tools/plotymlag.py index 96b5bf8..264a98d 100644 --- a/tools/plotymlag.py +++ b/tools/plotymlag.py @@ -5,7 +5,13 @@ import time size = 10 -lag = concore.tryparam("lag", 0) +lag = concore.tryparam("lag", 0) +if lag >= size: + logging.warning( + "Requested lag (%d) exceeds buffer size (%d). Clamping to %d.", + lag, size, size - 1 + ) + lag = size - 1 logging.info(f"plot ym with lag={lag}") concore.delay = 0.005