From 34652c4afa47dc9333753163077810cb1cec328c Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 5 Jun 2022 00:39:09 +0200 Subject: [PATCH] fix: draw non-null terminated strings --- .../src/thirdparty/libopenui/src/bitmapbuffer.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index cafa1d0d9..a95aea46a 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -18,6 +18,8 @@ */ #include +#include + #include "bitmapbuffer.h" #include "libopenui_depends.h" #include "libopenui_helpers.h" @@ -1064,10 +1066,15 @@ extern lv_color_t makeLvColor(uint32_t colorFlags); coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s, uint8_t len, LcdFlags flags) -{ +{ if (!s) return x; MOVE_OFFSET(); + // LVGL does not handle non-null terminated strings + static char buffer[256]; + strncpy(buffer, s, len); + buffer[len] = '\0'; + int height = getFontHeight(flags); if (y + height <= ymin || y >= ymax) { @@ -1094,7 +1101,7 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s, } lv_point_t p; - lv_txt_get_size(&p, s, font, label_draw_dsc.letter_space, + lv_txt_get_size(&p, buffer, font, label_draw_dsc.letter_space, label_draw_dsc.line_space, LV_COORD_MAX, 0); lv_coord_t lv_x = (lv_coord_t)x; @@ -1118,12 +1125,12 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s, } if (draw_ctx) { - lv_draw_label(draw_ctx, &label_draw_dsc, &coords, s, nullptr); + lv_draw_label(draw_ctx, &label_draw_dsc, &coords, buffer, nullptr); } #if !defined(BOOT) else if (canvas) { lv_canvas_draw_text(canvas, coords.x1, coords.y1, coords.x2 - coords.x1 + 1, - &label_draw_dsc, s); + &label_draw_dsc, buffer); } #endif