'%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 9 and 16 [-Werror=

HYPROWATER
Posts: 2
Joined: Fri Apr 29, 2022 8:50 am

'%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 9 and 16 [-Werror=

Postby HYPROWATER » Fri Apr 29, 2022 9:00 am

Hello,

I need help.

after Build I get this Error:

I need Help

/main/main.cpp:787:42: error: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 9 and 16 [-Werror=format-truncation=]
snprintf(ts_buf, ts_bufsize, "%04d-%02d-%02dT%02d:%02d:%02dZ",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../main/main.cpp:787:42: note: directive argument in the range [-2147483647, 2147483647]
../main/main.cpp:787:21: note: 'snprintf' output between 21 and 73 bytes into a destination of size 21
snprintf(ts_buf, ts_bufsize, "%04d-%02d-%02dT%02d:%02d:%02dZ",
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
utc_time.tm_year+1900,
~~~~~~~~~~~~~~~~~~~~~~
utc_time.tm_mon+1,
~~~~~~~~~~~~~~~~~~
utc_time.tm_mday,
~~~~~~~~~~~~~~~~~
utc_time.tm_hour,
~~~~~~~~~~~~~~~~~
utc_time.tm_min,
~~~~~~~~~~~~~~~~
utc_time.tm_sec
~~~~~~~~~~~~~~~
);
~
cc1plus.exe: some warnings being treated as errors
ninja: build stopped: subcommand failed.

jaffer
Posts: 5
Joined: Mon Feb 27, 2023 11:16 am

Re: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 9 and 16 [-Wer

Postby jaffer » Thu Jun 08, 2023 10:00 am

I had the same problem and solved it with the following the solution.

Add the following command to CMakeLists on the corresponding components:

Code: Select all

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
--------------------------------------------------------------------
我遇到了同样的问题,并通过以下方案解决了此问题:

在对应组件的对应CMakeLists文件最后添加以下命令:

Code: Select all

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
此外,你的年时间应该计算错了,struct tm结构体内的tm_year是基于1900开始计算的

Who is online

Users browsing this forum: No registered users and 83 guests