Skip to content

Commit

Permalink
Fix pgm_read_word for 64-bit host builds (#2844)
Browse files Browse the repository at this point in the history
Sanitizer caught issue with `pgm_read_dword` on 64-bit build, defined as `unsigned long` instead of `uint32_t`.

Suppress sanitizer `alignment` warnings for some FlashString methods where (64-bit) pointers are aligned to 32-bit boundaries. We need everything (including pointers) to be 32-bit aligned so this isn't a bug. (It's an optimisation thing.)
  • Loading branch information
mikee47 authored Jun 28, 2024
1 parent e029a62 commit 6570fd3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sming/Arch/Host/Components/libc/include/sys/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ bool isFlashPtr(const void* ptr);
#define PGM_P const char*
#define PGM_VOID_P const void*

#define pgm_read_byte(addr) (*(const unsigned char*)(addr))
#define pgm_read_word(addr) (*(const unsigned short*)(addr))
#define pgm_read_dword(addr) (*(const unsigned long*)(addr))
#define pgm_read_byte(addr) (*(const uint8_t*)(addr))
#define pgm_read_word(addr) (*(const uint16_t*)(addr))
#define pgm_read_dword(addr) (*(const uint32_t*)(addr))
#define pgm_read_float(addr) (*(const float*)(addr))

#define pgm_read_byte_near(addr) pgm_read_byte(addr)
Expand Down

0 comments on commit 6570fd3

Please sign in to comment.