adafruit / Adafruit-GFX-Library

Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
https://learn.adafruit.com/adafruit-gfx-graphics-library
Other
2.4k stars 1.55k forks source link

Please fix compiler warnings with -Wall #222

Open marcmerlin opened 5 years ago

marcmerlin commented 5 years ago

Adafruit git master gives me the following when all warnings on turned on in the arduino GUI

/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_SPITFT.cpp:902:6: warning: unused parameter 'block' [-Wunused-parameter]
 void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len,
      ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_SPITFT.cpp:902:6: warning: unused parameter 'bigEndian' [-Wunused-parameter]
In file included from /var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/stdio.h:6:0,
                 from /var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/stdio.h:63,
                 from /var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/Arduino.h:32,
                 from /home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.h:5,
                 from /home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:34:
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp: In member function 'void Adafruit_GFX::drawChar(int16_t, int16_t, unsigned char, uint16_t, uint16_t, uint8_t)':
/var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:74:85: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     #define pgm_read_dword(addr)            (*reinterpret_cast<const uint32_t*>(addr))
                                                                                     ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:60:42: note: in expansion of macro 'pgm_read_dword'
  #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
                                          ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:1076:43: note: in expansion of macro 'pgm_read_pointer'
         GFXglyph *glyph  = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
                                           ^
/var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:74:85: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     #define pgm_read_dword(addr)            (*reinterpret_cast<const uint32_t*>(addr))
                                                                                     ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:60:42: note: in expansion of macro 'pgm_read_dword'
  #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
                                          ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:1077:39: note: in expansion of macro 'pgm_read_pointer'
         uint8_t  *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
                                       ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp: In member function 'virtual size_t Adafruit_GFX::write(uint8_t)':
/var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:74:85: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     #define pgm_read_dword(addr)            (*reinterpret_cast<const uint32_t*>(addr))
                                                                                     ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:60:42: note: in expansion of macro 'pgm_read_dword'
  #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
                                          ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:1161:50: note: in expansion of macro 'pgm_read_pointer'
                 GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(
                                                  ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp: In member function 'void Adafruit_GFX::charBounds(char, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)':
/var/local/arduino-1.8.6-pre/portable/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:74:85: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     #define pgm_read_dword(addr)            (*reinterpret_cast<const uint32_t*>(addr))
                                                                                     ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:60:42: note: in expansion of macro 'pgm_read_dword'
  #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
                                          ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:1353:50: note: in expansion of macro 'pgm_read_pointer'
                 GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(
                                                  ^
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp: At global scope:
/home/merlin/Arduino/libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp:1515:6: warning: unused parameter 'i' [-Wunused-parameter]
 void Adafruit_GFX::invertDisplay(boolean i) {
ladyada commented 5 years ago

thanks, if you'd like to try to submit a PR to address it, looks like the ESP8266 compiler is picky!

marcmerlin commented 5 years ago

Sure @ladyada , although this is kind of crucial code that all your stuff depends on, so if the original author has time to look at it, I'd rather :) Just to be clear, to make sure it's not a compiler/chip issue, are you aware of the File/Preferences/Compiler Warnings setting? If so, try setting it to 'all' to see if it reproduces the same warnings. I find that it's safer to code with all warnings as it finds unused variables that are often typos/logic errors as well as indexes that run out of bounds on arrays, which has also found real bugs that had been missed by others before. I agree that the pgm* warnings look harmless, but you'll also notice

ladyada commented 5 years ago

yah please take a look and see if you spot any bugs. fixing compiler warnings is low priority and as you say, its crucial and a lot depends on it