refactor(splits): Minor cleanups to periph invocation

* Add strlcpy from public domain version.
* Leverage strlcpy to detect truncation of behavior dev strs, and log.
* Use `offsetof` for cleaner detection on peripheral side.
This commit is contained in:
Peter Johanson
2022-02-01 03:29:50 +00:00
committed by Pete Johanson
parent b8700eaaa1
commit 7430750428
5 changed files with 55 additions and 3 deletions

View File

@@ -51,8 +51,10 @@ static ssize_t split_svc_run_behavior(struct bt_conn *conn, const struct bt_gatt
// We run if:
// 1: We've gotten all the position/state/param data.
// 2: We have a null terminated string for the behavior device label.
const size_t behavior_dev_offset =
offsetof(struct zmk_split_run_behavior_payload, behavior_dev);
if ((end_addr > sizeof(struct zmk_split_run_behavior_data)) &&
payload->behavior_dev[end_addr - sizeof(struct zmk_split_run_behavior_data) - 1] == '\0') {
payload->behavior_dev[end_addr - behavior_dev_offset - 1] == '\0') {
struct zmk_behavior_binding binding = {
.param1 = payload->data.param1,
.param2 = payload->data.param2,