birkenfeld / ads-rs

Rust crate to access PLCs via the Beckhoff ADS protocol
https://crates.io/crates/ads
Apache License 2.0
40 stars 8 forks source link

decode_symbol_info panics when parsing ARRAY with negative indices such as ARRAY[-1..5] OF INT; #13

Closed andrewraytan closed 1 year ago

andrewraytan commented 1 year ago

I created a TwinCAT program with negative indices ARRAY[-1..5] OF INT; and tried parsing the symbols from the program.

The library panicked for reason "attempt to add with overflow" in line 258 of symbol.rs.

Stack trace looks something like this:

   0: std::panicking::begin_panic_handler
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:142
   2: core::panicking::panic
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:48
   3: ads::symbol::decode_symbol_info::decode_type_info
             at C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\ads-0.4.3\src\symbol.rs:258
   4: ads::symbol::decode_symbol_info
             at C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\ads-0.4.3\src\symbol.rs:296
   5: ads::symbol::get_symbol_info
             at C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\ads-0.4.3\src\symbol.rs:213
birkenfeld commented 1 year ago

Whoops, negative indices exist... Thanks for the report, will come up with a fix.