sparkfun / SparkFun_SX1509_Arduino_Library

Arduino library for the SX1509 16-I/O GPIO expander.
44 stars 38 forks source link

Fixes issue in SX1509::readWord(uint8_t, uint16_t *) #26

Open Willmac16 opened 9 months ago

Willmac16 commented 9 months ago

Existing implementation accessed memory it shouldn't, and didn't write both values to the target uint16_t.

Willmac16 commented 9 months ago

For reference, when the original code is run, my compiler spits out:

.pio/libdeps/teensymm/SX1509 IO Expander/src/SparkFunSX1509.cpp: In member function 'bool SX1509::readPin(uint8_t, bool*)':
.pio/libdeps/teensymm/SX1509 IO Expander/src/SparkFunSX1509.cpp:789:26: warning: array subscript 1 is outside array bounds of 'uint16_t [1]' {aka 'short unsigned int [1]'} [-Warray-bounds]
  789 |                 value[1] = dest[0];
      |                 ~~~~~~~~~^~~~~~~~~
.pio/libdeps/teensymm/SX1509 IO Expander/src/SparkFunSX1509.cpp:212:18: note: while referencing 'tempRegDir'
  212 |         uint16_t tempRegDir;