Skip to content

Commit 61a8a47

Browse files
committed
Ensure we don't create zero length waveforms
Also check and abort writes that are too long for the waveform
1 parent 40cb943 commit 61a8a47

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

softioc/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def _waveform(value, fields):
179179
length = fields.pop('length')
180180
datatype = initial_value.dtype
181181

182+
assert length > 0, 'Array cannot be of zero length'
183+
182184
fields['initial_value'] = initial_value
183185
fields['_wf_nelm'] = length
184186
fields['_wf_dtype'] = datatype

softioc/device.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ def _value_to_epics(self, value):
374374
# Because arrays are mutable values it's ever so easy to accidentially
375375
# call set() with a value which subsequently changes. To avoid this
376376
# common class of bug, at the cost of duplicated code and data, here we
377-
# ensure a copy is taken of the value, after pruning to length.
378-
return +value[:self._nelm]
377+
# ensure a copy is taken of the value.
378+
assert len(value) <= self._nelm, 'Value too long for waveform'
379+
return +value
379380

380381
def _epics_to_value(self, value):
381382
return value

0 commit comments

Comments
 (0)