mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-23 22:42:01 +08:00
refactor(printf) add printf-like function attribute to _lv_txt_set_text_vfmt and lv_label_set_text_fmt (#2332)
This improves static analysis and compiler warnings of incorrect format usage.
This commit is contained in:
+1
-1
@@ -483,7 +483,7 @@ void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
|
||||
* @param fmt `printf`-like format
|
||||
* @return pointer to the allocated text string.
|
||||
*/
|
||||
char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap)
|
||||
LV_FORMAT_ATTRIBUTE(1, 0) char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap)
|
||||
{
|
||||
/*Allocate space for the new text by using trick from C99 standard section 7.19.6.12*/
|
||||
va_list ap_copy;
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ extern "C" {
|
||||
#include "lv_area.h"
|
||||
#include "../font/lv_font.h"
|
||||
#include "lv_printf.h"
|
||||
#include "lv_types.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -141,7 +142,7 @@ void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len);
|
||||
* @param fmt `printf`-like format
|
||||
* @return pointer to the allocated text string.
|
||||
*/
|
||||
char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap);
|
||||
char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0);
|
||||
|
||||
/**
|
||||
* Decode two encoded character from a string.
|
||||
|
||||
@@ -80,6 +80,12 @@ typedef uint32_t lv_uintptr_t;
|
||||
#define _LV_CONCAT3(x, y, z) x ## y ## z
|
||||
#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z)
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__ ((format(printf, fmtstr, vararg)))
|
||||
#else
|
||||
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* @file lv_label.c
|
||||
*
|
||||
*/
|
||||
@@ -144,7 +144,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text)
|
||||
lv_label_refr_text(obj);
|
||||
}
|
||||
|
||||
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
|
||||
LV_FORMAT_ATTRIBUTE(2, 3) void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_ASSERT_NULL(fmt);
|
||||
|
||||
@@ -105,7 +105,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text);
|
||||
* @param fmt `printf`-like format
|
||||
* @example lv_label_set_text_fmt(label1, "%d user", user_num);
|
||||
*/
|
||||
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...);
|
||||
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3);
|
||||
|
||||
/**
|
||||
* Set a static text. It will not be saved by the label so the 'text' variable
|
||||
|
||||
Reference in New Issue
Block a user