Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential problem with wrong response in function decode_packed_coils #298

Open
fbrisa opened this issue Nov 18, 2024 · 0 comments
Open

Comments

@fbrisa
Copy link

fbrisa commented 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)

@fbrisa 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant