arduino/ArduinoCore-sam

Incorrect const in pgm_read_ptr

tttapa opened this issue · 0 comments

There seems to be bug in macro pgm_read_ptr macro in the pgmspace.h header.

#define pgm_read_ptr(addr) (*(const void **)(addr))

The cast to const void ** is incorrect, because it casts it to "a pointer to a pointer to a read-only object of any type".
I believe that the correct type would be void *const *, "a pointer to a read-only pointer to an object of any type". The pointer itself is in progmem, and therefore is read-only, but the pointee is not necessarily read-only, as it could be in static memory.

Discovered here: tttapa/Control-Surface#64