CmBacktrace icon indicating copy to clipboard operation
CmBacktrace copied to clipboard

KEIL AC6编译警告!!!

Open libangy opened this issue 3 years ago • 11 comments
trafficstars

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

libangy avatar Aug 15 '22 08:08 libangy

请问解决了吗

zhang-4411 avatar Sep 22 '22 05:09 zhang-4411

全部改成宏定义解决

zhang-4411 avatar Sep 22 '22 10:09 zhang-4411

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

q164129345 avatar Dec 05 '22 09:12 q164129345

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

zhang-4411 avatar Dec 05 '22 10:12 zhang-4411

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

q164129345 avatar Dec 05 '22 10:12 q164129345

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

q164129345 avatar Dec 06 '22 02:12 q164129345

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

libangy avatar Dec 06 '22 05:12 libangy

image

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

q164129345 avatar Dec 07 '22 12:12 q164129345

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

q164129345 avatar Dec 07 '22 12:12 q164129345

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

xjtuecho avatar Mar 17 '23 01:03 xjtuecho

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

wdfk-prog avatar Mar 17 '23 01:03 wdfk-prog