stevemarple / SoftWire

Software I2C implementation for Arduino and other Wiring-type environments
GNU Lesser General Public License v2.1
136 stars 31 forks source link

Fix incorrect switch-statement fallthru. #24

Closed bxparks closed 2 years ago

bxparks commented 2 years ago

The compiler issues the following warning message:

SoftWire.cpp:206:8: warning: this statement may fall through [-Wimplicit-fallthrough=] stop();

And the compiler is correct. The function incorrectly issues 2 stop() conditions, and returns 'timedOut' instead of 'nack' due to the incorrect fallthru.

stevemarple commented 2 years ago

Thanks for catching this. I'm surprised cppcheck hasn't caught this bug.

stevemarple commented 2 years ago

I have released v2.0.5 to include this fix and added @bxparks to the list of contributors.

Thanks, Steve

bxparks commented 2 years ago

It looks like cppcheck(1) removed that check around 2014/2015: https://sourceforge.net/p/cppcheck/discussion/general/thread/1b4c27f5/ because the author thinks that it generates too many false positives.

C++17 and C23 adds a [[fallthough]] annotation which is nice, but doesn't help Arduino code.

Most Arduino compilers on various Cores will catch this if you check the "Compiler warnings" box in the IDE. I sometimes run my Arduino code through clang++ on a Linux box, which will sometimes catch bugs that g++ does not.