diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-11-11 15:27:10 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-11-11 15:27:10 +0100 |
commit | a7a45b0e710dabb267859bf8794e19eefc173a7b (patch) | |
tree | 3d566113642c18daf61814517756cb97f193fec3 | |
parent | 7570b7061bd010a387aa9a34819ee33e77bbebdc (diff) | |
download | hourglass-a7a45b0e710dabb267859bf8794e19eefc173a7b.tar.gz hourglass-a7a45b0e710dabb267859bf8794e19eefc173a7b.tar.bz2 hourglass-a7a45b0e710dabb267859bf8794e19eefc173a7b.zip |
Fix i2c out of bounds write
Fixes longstanding bug that caused strange behavior wrt LED’s states.
-rw-r--r-- | i2c.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -72,6 +72,8 @@ void twInit () { bool twRequest (const twMode mode, const uint8_t address, const uint8_t subaddress, uint8_t * const data, const uint8_t count) { assert (twr.status == TWST_OK); + assert (count > 0); + assert (data != NULL); twr.mode = mode; twr.address = address; @@ -208,7 +210,7 @@ static void twIntRead () { if (status == TW_MR_DATA_ACK) { twr.data[twr.i] = TWDR; ++twr.i; - if (twr.i < twr.count-1) { + if (twr.i < twr.count) { /* read another byte, not the last one */ twFlushContRaw (); /* step stays the same */ @@ -225,8 +227,6 @@ static void twIntRead () { case 6: if (status == TW_MR_DATA_NACK) { - /* receive final byte, send stop */ - twr.data[twr.i] = TWDR; twStopRaw (); twr.status = TWST_OK; } else { |