Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix pgm_read_ptr in AVR pgmspace.h #118
Conversation
Originally, `pgm_read_ptr` used to cast its argument to `const void *`, i.e. a pointer to read-only data. This is incorrect, because the argument is a pointer to a pointer in "flash memory". You cannot cast it to `const void *` and then dereference it, because `void` is not an object type. Also, the pointer itself is read-only, but the data could in theory be mutable. The correct type should be `void *const *`, i.e. a pointer to a read-only pointer to any data.
I confirm that this change is necessary to fix the following error:
Please merge this pull request. |
Also looks good to me. One nitpick: I would have a small preference to use |
The core for ESP32 use |
The core for ESP8266 uses |
"Arduino STM32" uses |
As you see, there are many variants out there. |
But I'm saying that, AFAIU, |
It's not a matter of taste; they are different types:
|
Hm, seems I was wrong indeed, thanks for insisting. So with that out of the way, the PR as it is now is indeed correct, so I'm for merging it. Note that this also means that the SAMD and Arduino_STM32 versions are indeed also subtly broken (returning |
Thank you to both @bblanchon and @matthijskooijman |
Thanks !!! |
Originally,
pgm_read_ptr
used to cast its argument toconst void *
, i.e. a pointer to read-only data.This is incorrect, because the argument is a pointer to a pointer in "flash memory". You cannot cast it to
const void *
and then dereference it, becausevoid
is not an object type.Also, the pointer itself is read-only, but the data could in theory be mutable.
The correct type should be
void *const *
, i.e. a pointer to a read-only pointer to any data.