qmk_firmware/quantum
Jeff Epler 9632360caa
Use a macro to compute the size of arrays at compile time (#18044)
* Add ARRAY_SIZE and CEILING utility macros

* Apply a coccinelle patch to use ARRAY_SIZE

* fix up some straggling items

* Fix 'make test:secure'

* Enhance ARRAY_SIZE macro to reject acting on pointers

The previous definition would not produce a diagnostic for
```
int *p;
size_t num_elem = ARRAY_SIZE(p)
```
but the new one will.

* explicitly get definition of ARRAY_SIZE

* Convert to ARRAY_SIZE when const is involved

The following spatch finds additional instances where the array is
const and the division is by the size of the type, not the size of
the first element:
```
@ rule5a using "empty.iso" @
type T;
const T[] E;
@@

- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)

@ rule6a using "empty.iso" @
type T;
const T[] E;
@@

- sizeof(E)/sizeof(T)
+ ARRAY_SIZE(E)
```

* New instances of ARRAY_SIZE added since initial spatch run

* Use `ARRAY_SIZE` in docs (found by grep)

* Manually use ARRAY_SIZE

hs_set is expected to be the same size as uint16_t, though it's made
of two 8-bit integers

* Just like char, sizeof(uint8_t) is guaranteed to be 1

This is at least true on any plausible system where qmk is actually used.

Per my understanding it's universally true, assuming that uint8_t exists:
https://stackoverflow.com/questions/48655310/can-i-assume-that-sizeofuint8-t-1

* Run qmk-format on core C files touched in this branch

Co-authored-by: Stefan Kerkmann <karlk90@pm.me>
2022-08-30 10:20:04 +02:00
..
audio
backlight Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
bootmagic
debounce
encoder/tests
keymap_extras Fix DV_SCLN and DV_COLN in keymap_spanish_dvorak.h (#18043) 2022-08-15 18:41:05 +01:00
led_matrix
logging
painter
pointing_device [Core] Introduce pointing device specific debug messages (#17663) 2022-08-29 19:16:49 +02:00
process_keycode Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
rgb_matrix Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
rgblight
send_string Add missing SS_LOPT and SS_ROPT defines (#18175) 2022-08-27 09:41:10 +10:00
sequencer
split_common
wear_leveling
action.c
action.h
action_code.h
action_layer.c
action_layer.h
action_tapping.c
action_tapping.h
action_util.c
action_util.h
bitwise.c
bitwise.h
caps_word.c
caps_word.h
color.c
color.h
command.c
command.h
config_common.h
crc.c
crc.h
debounce.h
deferred_exec.c
deferred_exec.h
digitizer.c
digitizer.h
dip_switch.c Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
dip_switch.h
dynamic_keymap.c
dynamic_keymap.h
dynamic_macro.h
eeconfig.c
eeconfig.h
encoder.c Use TAP_CODE_DELAY for encoder mapping by default (#18098) 2022-08-28 21:53:08 -07:00
encoder.h Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
haptic.c
haptic.h
joystick.c
joystick.h
keyboard.c
keyboard.h
keycode.h
keycode_config.c
keycode_config.h
keycode_legacy.h
keymap.h
keymap_common.c
keymap_introspection.c Clean-up of #define _ADJUST 16 instances (#18182) 2022-08-27 23:13:44 -07:00
keymap_introspection.h
led.c
led.h
led_tables.c
led_tables.h
main.c
matrix.c
matrix.h
matrix_common.c
mousekey.c
mousekey.h
pointing_device_internal.h [Core] Introduce pointing device specific debug messages (#17663) 2022-08-29 19:16:49 +02:00
programmable_button.c
programmable_button.h
quantum.c
quantum.h
quantum_keycodes.h
quantum_keycodes_legacy.h
raw_hid.h
ring_buffer.h
secure.c Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
secure.h
sync_timer.c
sync_timer.h
utf8.c
utf8.h
util.h Use a macro to compute the size of arrays at compile time (#18044) 2022-08-30 10:20:04 +02:00
variable_trace.c
variable_trace.h
velocikey.c
velocikey.h
via.c
via.h
via_ensure_keycode.h
virtser.h
wpm.c
wpm.h