From 145443c65c340375572b7f611564b1ffb31ae010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 26 Sep 2017 20:18:26 +0200 Subject: [PATCH] Fix the computation of KEY_STATE_SIZE and the byte count to memset in BoolBytesToBits() --- left/src/slave_protocol_handler.h | 2 +- shared/bool_array_converter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/left/src/slave_protocol_handler.h b/left/src/slave_protocol_handler.h index f059c07..ec67b38 100644 --- a/left/src/slave_protocol_handler.h +++ b/left/src/slave_protocol_handler.h @@ -13,7 +13,7 @@ #define PROTOCOL_RESPONSE_GENERIC_ERROR 1 #define LEFT_KEYBOARD_HALF_KEY_COUNT (KEYBOARD_MATRIX_COLS_NUM*KEYBOARD_MATRIX_ROWS_NUM) - #define KEY_STATE_SIZE (LEFT_KEYBOARD_HALF_KEY_COUNT/8 + 1) + #define KEY_STATE_SIZE (LEFT_KEYBOARD_HALF_KEY_COUNT/8 + (LEFT_KEYBOARD_HALF_KEY_COUNT % 8 ? 1 : 0)) // Variables: diff --git a/shared/bool_array_converter.c b/shared/bool_array_converter.c index f174995..83f3619 100644 --- a/shared/bool_array_converter.c +++ b/shared/bool_array_converter.c @@ -3,7 +3,7 @@ void BoolBytesToBits(uint8_t *srcBytes, uint8_t *dstBits, uint8_t byteCount) { - memset(dstBits, 0, byteCount/8 + 1); + memset(dstBits, 0, byteCount/8 + (byteCount % 8 ? 1 : 0)); for (uint8_t i=0; i