armink / CmBacktrace

Advanced fault backtrace library for ARM Cortex-M series MCU | ARM Cortex-M 系列 MCU 错误追踪库

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KEIL AC6编译警告!!!

libangy opened this issue · comments

环境:KEIL5.29
编译器:AC6.13.1
FreeRTOS: V10.4.6,task.c中已增加uxSizeOfStack

cmb_cfg.h:

#define cmb_println(...) printf(VA_ARGS);printf("\r\n");/* e.g., printf(VA_ARGS);printf("\r\n") */

#define CMB_USING_OS_PLATFORM
#define CMB_OS_PLATFORM_TYPE CMB_OS_PLATFORM_FREERTOS

#define CMB_CPU_PLATFORM_TYPE CMB_CPU_ARM_CORTEX_M4
/* enable dump stack information /
#define CMB_USING_DUMP_STACK_INFO
/
language of print information */
#define CMB_PRINT_LANGUAGE CMB_PRINT_LANGUAGE_ENGLISH // (default) or CMB_PRINT_LANGUAGE_CHINESE */

编译出现30个警告:
cm_backtrace.c(168): warning: format string is not a string literal (potentially insecure) [-Wformat-security]
cmb_println(print_info[PRINT_MAIN_STACK_CFG_ERROR]);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmb_cfg.h(35): note: expanded from macro 'cmb_println'
#define cmb_println(...) printf(VA_ARGS);printf("\r\n");/* e.g., printf(VA_ARGS);printf("\r\n") /
^~~~~~~~~~~
cm_backtrace.c(168): note: treat the string as an argument to avoid this
cmb_println(print_info[PRINT_MAIN_STACK_CFG_ERROR]);
^
"%s",
cmb_cfg.h(35): note: expanded from macro 'cmb_println'
#define cmb_println(...) printf(VA_ARGS);printf("\r\n");/
e.g., printf(VA_ARGS);printf("\r\n") /
^
cm_backtrace.c(256): warning: format string is not a string literal (potentially insecure) [-Wformat-security]
cmb_println(print_info[PRINT_THREAD_STACK_INFO]);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmb_cfg.h(35): note: expanded from macro 'cmb_println'
#define cmb_println(...) printf(VA_ARGS);printf("\r\n");/
e.g., printf(VA_ARGS);printf("\r\n") */
^~~~~~~~~~~
../Middlewares/CmBacktrace/cm_backtrace/cm_backtrace.c(256): note: treat the string as an argument to avoid this
……

有什么办法可以消除这些警告吗????@armink

请问解决了吗

全部改成宏定义解决

我也碰到同样的问题.....能详细说一下解决方案吗??

AC6
#define PRINT "ABC"
const char *str1 = "ABC";
printf("str1 ");//warning
printf("%s",str1 );//no warning
printf("PRINT " );//no warning
/*****************************************************************************/
#define PRINT_MAIN_STACK_CFG_ERROR "ERROR: Unable to get the main stack information, please check the configuration of the main stack"
#define PRINT_FIRMWARE_INFO "Firmware name: %s, hardware version: %s, software version: %s"
#define PRINT_ASSERT_ON_THREAD "Assert on thread %s"
#define PRINT_ASSERT_ON_HANDLER "Assert on interrupt or bare metal(no OS) environment"
#define PRINT_THREAD_STACK_INFO "===== Thread stack information ====="
....................................................................

3Q......这也是一种思路。

我发现,就算用宏定义清除了警告。。。在AC6上还是不正常,打印出来的信息不正常。。。

解决方案:Option for Targets -> C/C++(AC6) -> Misc Controls -> -Wno-format-security

image

很奇怪的是...换成AC6之后的打印有问题。。。

解决方案:Option for Targets -> C/C++(AC6) -> Misc Controls -> -Wno-format-security
警告消除了。。。但是打印的信息有问题了。。
image

commented

为了支持中文显示搞的东西,这种库完全没有必要支持中文显示。我给清理了一下,去掉了中文支持,兼容了C89,剩4个文件,解压后丢到自己的工程中即可。很好用,不需要文档,直接看代码即可。
cm_backtrace.zip

或许跟编码格式有关系,使用GB2312的中文可能不正常.UTF8格式的中文试一下或许可以