Skip to content

Commit 11e04a2

Browse files
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.
1 parent 3b6756b commit 11e04a2

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

tools/plotymlag.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
import numpy as np
33
import matplotlib.pyplot as plt
44
import time
5+
import logging
56

67
size = 10
7-
lag = concore.tryparam("lag", 0)
8+
lag = concore.tryparam("lag", 0)
9+
if lag >= size:
10+
logging.warning(
11+
"Requested lag (%d) exceeds buffer size (%d). Clamping to %d.",
12+
lag, size, size - 1
13+
)
14+
lag = size - 1
815
print("plot ym with lag="+str(lag))
916

1017
concore.delay = 0.005

0 commit comments

Comments
 (0)