Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing parentheses in macros can lead to unintended behavior #585

Open
vomindoraan opened this issue Jan 4, 2019 · 0 comments
Open

Missing parentheses in macros can lead to unintended behavior #585

vomindoraan opened this issue Jan 4, 2019 · 0 comments

Comments

@vomindoraan
Copy link
Contributor

vomindoraan commented Jan 4, 2019

https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/common/progmem.h#L8-L9

The arguments, p, should be parenthesized. Otherwise, calling pgm_read_word(ptr + i) might result in the wrong address being calculated due to ptr being type cast before addition. Other macros in the codebase might have the same issue.

Solution: put p in parentheses.

#   define pgm_read_byte(p)     *((unsigned char*)(p))
#   define pgm_read_word(p)     *((uint16_t*)(p))

Discovered in qmk/qmk_firmware#4775.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant