mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
633 stars 209 forks source link

warning: left shift count >= width of type #280

Closed frazar closed 5 years ago

frazar commented 5 years ago

Compiling LMIC on the latest commit (6e5ebbe) with the Arduino IDE yields the following warnings:

/home/frazar/Arduino/libraries/MCCI_LoRaWAN_LMIC_library/src/lmic/lmic.c: In function 'reportEventNoUpdate':
/home/frazar/Arduino/libraries/MCCI_LoRaWAN_LMIC_library/src/lmic/lmic.c:473:41: warning: left shift count >= width of type [-Wshift-count-overflow]
     if (pOnEvent != NULL && (evSet & (1u<<EV_RXSTART)) == 0)
                                         ^
/home/frazar/Arduino/libraries/MCCI_LoRaWAN_LMIC_library/src/lmic/lmic.c:507:44: warning: left shift count >= width of type [-Wshift-count-overflow]
     if ((evSet & ((1u<<EV_TXCOMPLETE) | (1u<<EV_TXCANCELED))) != 0) {

This is because 1u is of type unsigned int (16 bits on Arduino), while EV_RXSTART is 19.

terrillmoore commented 5 years ago

Actually.... this code base originally comes from an ARM-based platform and was backported to 16-bit platforms. Having (years ago) maintained a code base that was on 16 bit and 32-bit platforms, I don't know that all the rules have been followed. SInce I don't have AVR platforms to test with (or the time to test), this kind of thing is going to be an ongoing problem. Sorry.