From f0195246001732d6c8688dfc59e37e49052408e3 Mon Sep 17 00:00:00 2001 From: Mike Szczys Date: Tue, 27 Aug 2024 21:56:11 -0500 Subject: [PATCH] fix(display): widgets: increase buffer size for symbols Increase buffer size used for placing LVGL symbols on displays. This prevents array overflow warnings as discussed in #2444. Also convert one sprintf to snprintf to ensure the buffers are always null terminated and never overflow. Signed-off-by: Mike Szczys --- app/src/display/widgets/layer_status.c | 8 ++++---- app/src/display/widgets/output_status.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/display/widgets/layer_status.c b/app/src/display/widgets/layer_status.c index 73c2268e4cc..19e25d93312 100644 --- a/app/src/display/widgets/layer_status.c +++ b/app/src/display/widgets/layer_status.c @@ -24,13 +24,13 @@ struct layer_status_state { static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) { if (state.label == NULL) { - char text[7] = {}; + char text[8] = {}; - sprintf(text, LV_SYMBOL_KEYBOARD " %i", state.index); + snprintf(text, sizeof(text), LV_SYMBOL_KEYBOARD " %i", state.index); lv_label_set_text(label, text); } else { - char text[13] = {}; + char text[14] = {}; snprintf(text, sizeof(text), LV_SYMBOL_KEYBOARD " %s", state.label); @@ -64,4 +64,4 @@ int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_ lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget) { return widget->obj; -} \ No newline at end of file +} diff --git a/app/src/display/widgets/output_status.c b/app/src/display/widgets/output_status.c index da29a95f393..7b6f948699a 100644 --- a/app/src/display/widgets/output_status.c +++ b/app/src/display/widgets/output_status.c @@ -35,7 +35,7 @@ static struct output_status_state get_state(const zmk_event_t *_eh) { } static void set_status_symbol(lv_obj_t *label, struct output_status_state state) { - char text[10] = {}; + char text[20] = {}; switch (state.selected_endpoint.transport) { case ZMK_TRANSPORT_USB: