adafruit / Adafruit_EPD

e-paper display driver for Arduino
140 stars 56 forks source link

Fix a couple of warnings #65

Closed hathach closed 2 years ago

hathach commented 2 years ago

come across these warnings when doing some work with nrf52.

/home/runner/Arduino/libraries/Adafruit_EPD/src/Adafruit_MCPSRAM.cpp: In member function 'uint8_t Adafruit_MCPSRAM::read8(uint16_t, uint8_t)':
  /home/runner/Arduino/libraries/Adafruit_EPD/src/Adafruit_MCPSRAM.cpp:241:24: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
    241 |         buf[i] = (buf[i] << 1) | digitalRead(_miso);
        |                   ~~~~~^
  /home/runner/Arduino/libraries/Adafruit_EPD/src/Adafruit_MCPSRAM.cpp:259:11: note: 'c' was declared here
    259 |   uint8_t c;
        |           ^
hathach commented 2 years ago

thank for the approval :smile:

caternuson commented 2 years ago

LGTM.

This one seems a bit odd though

    241 |         buf[i] = (buf[i] << 1) | digitalRead(_miso);

Why is it complaining about c, but flagging buf?

hathach commented 2 years ago

it is due to the usage of read8(), used by most example sketch

https://github.com/adafruit/Adafruit_EPD/blob/129f1d062597670e0eaa63796e3e576c672738ba/src/Adafruit_MCPSRAM.cpp#L259-L263

which passed uninitialized variable 'c'. GCC becomes too smart, it now looks through the whole call-stack and it won't throw warnings if we actually initialize 'c'. Though it may warn if other read variant is used such as read16(). So I think we are better to fix this here.