Skip to content

Commit cd4ba4c

Browse files
authored
Fix pgm_read_ptr in AVR pgmspace.h
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.
1 parent 45e4e5a commit cd4ba4c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: api/deprecated-avr-comp/avr/pgmspace.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef const void* uint_farptr_t;
103103
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
104104
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
105105
#define pgm_read_float(addr) (*(const float *)(addr))
106-
#define pgm_read_ptr(addr) (*(const void *)(addr))
106+
#define pgm_read_ptr(addr) (*(void *const *)(addr))
107107

108108
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
109109
#define pgm_read_word_near(addr) pgm_read_word(addr)

0 commit comments

Comments
 (0)