attie/libxbee3

Overflow in libxbee::Pkt::getData() when handling large PAN ID values?

Closed this issue · 1 comments

Hi,

when reading (or writing/setting) the PAN ID value of any xbee1 device (in my case a Digi ConnectPort X2D), I'm experiencing what I think is a bug whenever the value of any of the two fields used to represent the PAN ID is >= 0x80. Example: If the PAN ID is set to 0x7f00, then reading this will result in a bit-representation of the first of the two fields (representing the 0x7f part; on my machine) that reads:
00000000000000000000000001111111
When altering the ID to (e.g.) 0x9000, this first field becomes
11111111111111111111111110010000
The expected value would have been
00000000000000000000000010010000

Speculation about the origin: In libxbee::Pkt::getData(), the data stored as "unsigned char" inside the xbee_pkt struct is cast to a char*, so we lose half the range of allowed values.

A workaround is to access the underlying data from the struct by ::getHnd()->data. Still I guess it would be nice to have the getData() method working for all values, hence I wanted to report.

I hope any of the above makes sense.

The problem was (of course) on my end. When printing the data, I had missed a conversion from char to unsigned char before converting the number to an integer. Sorry for the noise.