From 12cd58419fc78af7bc2c68c8d09012853e636822 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Wed, 24 Jan 2024 17:46:34 +0800 Subject: [PATCH] fix(assert): add new macro to format assert message (#5453) Signed-off-by: Xu Xingliang --- src/display/lv_display.c | 8 ++++---- src/misc/lv_assert.h | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/display/lv_display.c b/src/display/lv_display.c index d67a9a44b9..313602a3ab 100644 --- a/src/display/lv_display.c +++ b/src/display/lv_display.c @@ -406,8 +406,8 @@ void lv_display_set_buffers(lv_display_t * disp, void * buf1, void * buf2, uint3 LV_ASSERT_MSG(w != 0 && h != 0, "display resolution is 0"); /* buf1 or buf2 is not aligned according to LV_DRAW_BUF_ALIGN */ - LV_ASSERT_MSG(buf1 == lv_draw_buf_align(buf1, cf), "buf1 is not aligned: %p", buf1); - LV_ASSERT_MSG(buf2 == NULL || buf2 == lv_draw_buf_align(buf2, cf), "buf2 is not aligned: %p", buf2); + LV_ASSERT_FORMAT_MSG(buf1 == lv_draw_buf_align(buf1, cf), "buf1 is not aligned: %p", buf1); + LV_ASSERT_FORMAT_MSG(buf2 == NULL || buf2 == lv_draw_buf_align(buf2, cf), "buf2 is not aligned: %p", buf2); uint32_t stride = lv_draw_buf_width_to_stride(w, cf); if(render_mode == LV_DISPLAY_RENDER_MODE_PARTIAL) { @@ -416,8 +416,8 @@ void lv_display_set_buffers(lv_display_t * disp, void * buf1, void * buf2, uint3 LV_ASSERT_MSG(h != 0, "the buffer is too small"); } else { - LV_ASSERT_MSG(stride * h <= buf_size, "%s mode requires screen sized buffer(s)", - render_mode == LV_DISPLAY_RENDER_MODE_FULL ? "FULL" : "DIRECT"); + LV_ASSERT_FORMAT_MSG(stride * h <= buf_size, "%s mode requires screen sized buffer(s)", + render_mode == LV_DISPLAY_RENDER_MODE_FULL ? "FULL" : "DIRECT"); } lv_draw_buf_init(&disp->_static_buf1, w, h, cf, stride, buf1, buf_size); diff --git a/src/misc/lv_assert.h b/src/misc/lv_assert.h index 1b1b3b174d..c9dc849c76 100644 --- a/src/misc/lv_assert.h +++ b/src/misc/lv_assert.h @@ -42,10 +42,18 @@ extern "C" { } \ } while(0) -#define LV_ASSERT_MSG(expr, format, ...) \ +#define LV_ASSERT_MSG(expr, msg) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + +#define LV_ASSERT_FORMAT_MSG(expr, format, ...) \ do { \ if(!(expr)) { \ - LV_LOG_ERROR("Asserted at expression: %s " format , #expr, ##__VA_ARGS__); \ + LV_LOG_ERROR("Asserted at expression: %s " format , #expr, __VA_ARGS__); \ LV_ASSERT_HANDLER \ } \ } while(0)