Problem with optimization with Gcc on snprintf and FreeRTOS queue.c
I have compilation warning only with -O2 optimization (no warning with -O0) and i don't understand why, the code seems to be correct.
My environnement: STM32F103VD + STM32CubeIDE V1.2.0 (Gcc 7.3.1)
The code is the following for the first warning:
#define REC_DATE_HOUR_LENGTH (7u)
static CHAR acRecordDate[REC_DATE_HOUR_LENGTH] = {0};
snprintf((char*)acRecordDate,REC_DATE_HOUR_LENGTH,"%.2d%.2d%.2d", sDateTime.u8Day, sDateTime.u8Month, (U8)sDateTime.u16Year);This line of code introduces the following warning:
warning: '%.2d' directive output may be truncated writing between 2 and 3 bytes into a region of size between 1 and 3 [-Wformat-truncation=]I think the warning is a false positive. The output directive %.2d limit to two bytes the writing in acRecordDate buffer. Therefore, the REC_DATE_HOUR_LENGTH = 7 is sufficient and no warning has to be raised.
Another warning is in FreeRTOS queue management. And i clearly don't understand why it's generated.
The warning is:
FreeRTOS/queue.c:2067:3: warning: argument 2 null where non-null expected [-Wnonnull]The line of code:
( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */This warning is generated by -finline-small-functions optimization option.
So if someone solve these problems, any help is really appreciated !
Best regards,
JLM.