rambo / TinyWire

My modifications to TinyWire Arduino libs
284 stars 121 forks source link

Fix index overflow issue in examples #9

Closed rallyemax closed 10 years ago

rallyemax commented 10 years ago

All three examples contained a bug where the reg_position index overflows too early due to a greater-than-or-equal comparison to reg_size_lessone. One solution is to replace the greater-than-or-equal comparison operator with a greater-than operator. The better solution is to retain the >= operator, but to remove entirely the reg_size_lessone variable. It is somewhat clumsy to store as a separate variable another variable that has been decremented by one.

rambo commented 10 years ago

Yeah, I got this nasty feeling that the modulo I was using earlier would be expensive and then obviously had some brainfart when fixing that...