From 9632360caa5e6511b0ec13cb4c55eb64408232b5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 30 Aug 2022 03:20:04 -0500 Subject: 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 --- keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'keyboards/handwired/lagrange') diff --git a/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c b/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c index c2eb4406d1..bc5b025b48 100644 --- a/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c +++ b/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c @@ -191,8 +191,8 @@ void keyboard_post_init_user(void) { const pin_t pins[] = {D0, D1, D2}; uint8_t i, j; - for (i = 0 ; i < sizeof(pins) / sizeof(pins[0]) + 2 ; i += 1) { - for (j = 0 ; j < sizeof(pins) / sizeof(pins[0]) ; j += 1) { + for (i = 0 ; i < ARRAY_SIZE(pins) + 2 ; i += 1) { + for (j = 0 ; j < ARRAY_SIZE(pins); j += 1) { setPinOutput(pins[j]); writePin(pins[j], (j == i || j == i - 1)); } -- cgit v1.2.3 From bad8c5992bf68b6f2218b9b7a0b31c6ee7a03796 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 17 Oct 2022 23:45:23 +1100 Subject: Remove legacy sendstring keycodes (#18749) --- keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'keyboards/handwired/lagrange') diff --git a/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c b/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c index bc5b025b48..5f221904e9 100644 --- a/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c +++ b/keyboards/handwired/lagrange/keymaps/dpapavas/keymap.c @@ -125,7 +125,7 @@ CHOREOGRAPH(TD_RGHT, /* Send a complex macro: C-x C-s Mod-t up. (Save in * Emacs, switch to terminal and recall previous command, * hopefully a compile command.) */ - SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X) SS_TAP(X_S) SS_UP(X_LCTRL) + SEND_STRING(SS_DOWN(X_LCTL) SS_TAP(X_X) SS_TAP(X_S) SS_UP(X_LCTL) SS_DOWN(X_LGUI) SS_TAP(X_T) SS_UP(X_LGUI) SS_TAP(X_UP)), layer_invert(1)); @@ -134,9 +134,9 @@ CHOREOGRAPH(TD_RGHT, * just sends C-x. */ CHOREOGRAPH(TD_C_X, - SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X)), - SEND_STRING(SS_UP(X_LCTRL)), - SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X) SS_UP(X_LCTRL)),); + SEND_STRING(SS_DOWN(X_LCTL) SS_TAP(X_X)), + SEND_STRING(SS_UP(X_LCTL)), + SEND_STRING(SS_DOWN(X_LCTL) SS_TAP(X_X) SS_UP(X_LCTL)),); qk_tap_dance_action_t tap_dance_actions[] = { STEPS(TD_LEFT), STEPS(TD_RGHT), STEPS(TD_C_X) -- cgit v1.2.3 From 1cb1a5a3744dc569fbe25c44004d860241fd26b1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 21 Oct 2022 12:04:11 +1100 Subject: Remove legacy Grave Escape keycodes (#18787) --- keyboards/handwired/lagrange/keymaps/default/keymap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboards/handwired/lagrange') diff --git a/keyboards/handwired/lagrange/keymaps/default/keymap.c b/keyboards/handwired/lagrange/keymaps/default/keymap.c index db624e9be0..d5f73a8fed 100644 --- a/keyboards/handwired/lagrange/keymaps/default/keymap.c +++ b/keyboards/handwired/lagrange/keymaps/default/keymap.c @@ -25,7 +25,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( /* Left hand */ /* Right hand */ - KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, TT(1), + QK_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, TT(1), KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, -- cgit v1.2.3 From 002b58f0e4ea64eb5b06e36d988160bbb907cb83 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 27 Oct 2022 21:19:16 +1100 Subject: Normalise Space Cadet keycodes (#18864) --- keyboards/handwired/lagrange/keymaps/default/keymap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboards/handwired/lagrange') diff --git a/keyboards/handwired/lagrange/keymaps/default/keymap.c b/keyboards/handwired/lagrange/keymaps/default/keymap.c index d5f73a8fed..1c38de29f5 100644 --- a/keyboards/handwired/lagrange/keymaps/default/keymap.c +++ b/keyboards/handwired/lagrange/keymaps/default/keymap.c @@ -30,7 +30,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, - KC_LCPO, KC_INS, KC_LBRC, MINS_ALT, KC_BSPC, KC_DEL, KC_PSCR, KC_PAUSE, KC_ENT, KC_SPC, EQL_ALT, KC_RBRC, KC_DEL, KC_RCPC, + SC_LCPO, KC_INS, KC_LBRC, MINS_ALT, KC_BSPC, KC_DEL, KC_PSCR, KC_PAUSE, KC_ENT, KC_SPC, EQL_ALT, KC_RBRC, KC_DEL, SC_RCPC, HOME_GUI, KC_PGUP, KC_END, KC_LEFT, KC_UP, RGHT_GUI, KC_PGDN, KC_DOWN ), -- cgit v1.2.3