-
-
Notifications
You must be signed in to change notification settings - Fork 40.2k
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
Add missing parentheses to some important macros #4775
Conversation
Tested AVR and ARM real quickly, and doesn't appear to be any impact. Can't test ATSAM unless somebody wants to ship a massdrop board to me for testing |
After a bit of searching through the codebase, I think these are the only potentially problematic lines: As textdrivers/avr/analog.c:42drivers/avr/pro_micro.h:134 drivers/avr/ssd1306.c:288 drivers/qwiic/micro_oled.c:615 drivers/qwiic/micro_oled.c:616 drivers/qwiic/micro_oled.c:617 drivers/qwiic/micro_oled.c:618 drivers/qwiic/micro_oled.c:619 drivers/qwiic/micro_oled.c:636 drivers/qwiic/micro_oled.c:662 drivers/qwiic/micro_oled.c:683 keyboards/comet46/lib/keylogger.c:282 keyboards/comet46/ssd1306.c:300 keyboards/crkbd/pro_micro.h:132 keyboards/crkbd/ssd1306.c:300 keyboards/helix/pro_micro.h:134 keyboards/helix/ssd1306.c:298 keyboards/lily58/ssd1306.c:300 keyboards/minidox/pro_micro.h:134 keyboards/sol/common/ssd1306.c:292 keyboards/zeal60/rgb_backlight.c:296 keyboards/zeal60/rgb_backlight.c:344 quantum/process_keycode/process_steno.c:138 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:141 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:142 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:143 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:145 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:146 tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h:147 tmk_core/protocol/usb_hid/arduino-1.0.1/variants/leonardo/pins_arduino.h:67 tmk_core/protocol/vusb/usbdrv/usbportability.h:129 |
However, these lines are only problematic if the If the pointer type matches, then it will work with both the parenthesized and non-parenthesized version, since the size doesn't change and thus the pointer arithmetic stays the same. I'll go through the above lines and see which ones have pointers that don't match and would therefore break with the proposed changes. |
Zeal60 part works |
b3f1836
to
7211391
Compare
I've checked all of the potentially problematic lines listed above, and the types match in each of them! So these changes shouldn't introduce any problems, and this PR should be good to go. |
* 'master' of https://github.com/qmk/qmk_firmware: (63 commits) Keymap: ave-63's iris layout (qmk#4812) Update bakingpy 4x12 keymap and add test mode for debugging/development (qmk#4810) Fix Mac mute keycode (qmk#4809) Add KBD75 keymap (qmk#4808) Fix pinout of split hand and LED, remove flip half option Tidy up Mod-Tap shortcuts (qmk#4806) Add missing parentheses to some important macros (qmk#4775) Keyboard: Downbubble refactor and Configurator fix (qmk#4798) Alternate keymap for Alpha keyboard, enjoy! (qmk#4797) Keymap: Added Model F-inspired layout for YMD[K]96 (qmk#4777) Improve consistency in UNICODEMAP code and docs, update docs/understanding_qmk (qmk#4774) Update to arm_atsam wait and timer routines Add Downbubble to Handwired repository (qmk#4794) Final HS60v2 changes. (qmk#4790) Keyboard: Fractal layout macro and readme cleanup (qmk#4789) Keymap: added my espectro keymap (qmk#4791) Keyboard: Numbrero: Configurator fix and code tidy (qmk#4787) Keyboard: Tradestation code tidy and readme refactor (qmk#4784) Keyboard: update readme with ps2avr flashing instructions (qmk#4776) add Pinky keyboard (qmk#4748) ...
* Add missing parentheses to quantum_keycodes macros * Add missing parentheses to progmem macros
* Add missing parentheses to quantum_keycodes macros * Add missing parentheses to progmem macros
* Add missing parentheses to quantum_keycodes macros * Add missing parentheses to progmem macros
Add missing parentheses around arguments in macros like
LT
,MO
,TT
,pgm_read_byte
etc.Description
This is done to prevent unintended grouping of operands due to operator precedence. Take the
MO
macro in its current state, for example:Calling this macro with e.g.
MO(cond ? _RAISE : _LOWER)
would result in unexpected behavior. The macro would be expanded like so:(QK_MOMENTARY | (cond ? _RAISE : _LOWER & 0xFF))
. Then, because of operator precedence,_LOWER & 0xFF
would be grouped together, which likely isn't what was intended.To fix this, we instead define
MO
as follows:Same goes for
If we call that with
pgm_read_dword(unicode_map + index)
,unicode_map
will be cast to a pointer before addition, likely resulting in the wrong address being calculated due to how pointer arithmetic works.The argument,
p
, must be wrapped in parentheses:This is a common pitfall in C. Macro arguments should always be parenthesized. See this SO question for more information.
Types of changes
Checklist: