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:
Avamander
2021-07-11 15:19:51 -04:00
committed by GitHub
parent ef41450ed8
commit 078eaa009d
5 changed files with 12 additions and 5 deletions
+1 -1
View File
@@ -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
View File
@@ -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.
+6
View File
@@ -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
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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