Skip to content

Commit

Permalink
fix(display): widgets: increase buffer size for symbols
Browse files Browse the repository at this point in the history
Increase buffer size used for placing LVGL symbols on displays. This
prevents array overflow warnings as discussed in zmkfirmware#2444.

Also convert one sprintf to snprintf to ensure the buffers are always
null terminated and never overflow.

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys authored and petejohanson committed Aug 28, 2024
1 parent 6946ca8 commit f019524
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/src/display/widgets/layer_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/src/display/widgets/output_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f019524

Please sign in to comment.