You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the function decode_packed_coils under codec/mods.rs takes 2 arguments, one is the byte array with the list of the bytes to unpack, the other is the number of element to iterate
there is a situation where the bytes count is less then count / 8 and the internal "for" crashes the whole program
(I discovered it having a device answering me with wrong data)
I solved it (a fast bugfix to avoid all program to crash) inserting an if statement (I know it is not elegant)
for i in 0usize..count.into() { if i / 8 < bytes.len() { res.push((bytes[i / 8] >> (i % 8)) & 0b1 > 0); } }
I understand you do not expect the device to answer with inconsistent data, but it may still happen (especially with a RS 232 or 485 connection)
I wonder what could be a final solution (if any)
The text was updated successfully, but these errors were encountered:
fbrisa
changed the title
potential problem with wrong response in function unpack_coils
potential problem with wrong response in function decode_packed_coils
Nov 18, 2024
the function decode_packed_coils under codec/mods.rs takes 2 arguments, one is the byte array with the list of the bytes to unpack, the other is the number of element to iterate
there is a situation where the bytes count is less then count / 8 and the internal "for" crashes the whole program
(I discovered it having a device answering me with wrong data)
I solved it (a fast bugfix to avoid all program to crash) inserting an if statement (I know it is not elegant)
for i in 0usize..count.into() { if i / 8 < bytes.len() { res.push((bytes[i / 8] >> (i % 8)) & 0b1 > 0); } }
I understand you do not expect the device to answer with inconsistent data, but it may still happen (especially with a RS 232 or 485 connection)
I wonder what could be a final solution (if any)
The text was updated successfully, but these errors were encountered: