armink / CmBacktrace

Advanced fault backtrace library for ARM Cortex-M series MCU | ARM Cortex-M 系列 MCU 错误追踪库
MIT License
1.71k stars 661 forks source link

KEIL AC6编译警告!!! #64

Open libangy opened 2 years ago

libangy commented 2 years ago

环境: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

zhang-4411 commented 2 years ago

请问解决了吗

zhang-4411 commented 2 years ago

全部改成宏定义解决

q164129345 commented 1 year ago

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

zhang-4411 commented 1 year ago

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 ====="

....................................................................

q164129345 commented 1 year ago

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

q164129345 commented 1 year ago

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

libangy commented 1 year ago

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

q164129345 commented 1 year ago

image

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

q164129345 commented 1 year ago

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

xjtuecho commented 1 year ago

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

wdfk-prog commented 1 year ago

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