Skip to content

potential problem with wrong response in function decode_packed_coils #298

Open
@fbrisa

Description

@fbrisa

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions