https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88780
Arjan van Vught <arjan.van.vught at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |arjan.van.vught at gmail dot
com
--- Comment #5 from Arjan van Vught <arjan.van.vught at gmail dot com> ---
(In reply to Pei JIA from comment #4)
> gcc 9.3 in Ubuntu 20.04, this bug comes back????
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This code:
strncpy(m_SourceName, pSourceName, E131_SOURCE_NAME_LENGTH - 1);
m_SourceName[E131_SOURCE_NAME_LENGTH - 1] = '\0';
gives:
g++ -DNDEBUG -D_TIME_STAMP_YEAR_=2020 -D_TIME_STAMP_MONTH_=5
-D_TIME_STAMP_DAY_=26 -I./include -I../lib-hal/include -I../lib-debug/include
-I../lib-lightset/include -I../lib-properties/include -I../lib-hal/include
-I../lib-network/include -O2 -Wall -Werror -Wextra -Wpedantic -Wunused
-Wsign-conversion -fno-rtti -fno-exceptions -fno-unwind-tables
-Wnon-virtual-dtor -Wuseless-cast -Wold-style-cast -std=c++11 -c
src/e131bridge.cpp -o build_linux/src/e131bridge.o
In file included from /usr/include/string.h:495,
from src/e131bridge.cpp:29:
In function ‘char* strncpy(char*, const char*, size_t)’,
inlined from ‘void E131Bridge::SetSourceName(const char*)’ at
src/e131bridge.cpp:159:9,
inlined from ‘E131Bridge::E131Bridge()’ at src/e131bridge.cpp:88:15,
inlined from ‘E131Bridge::E131Bridge()’ at src/e131bridge.cpp:51:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char*
__builtin_strncpy(char*, const char*, long unsigned int)’ output may be
truncated copying 63 bytes from a string of length 63
[-Werror=stringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Workaround:
#if (__GNUC__ > 8)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
strncpy(m_SourceName, pSourceName, E131_SOURCE_NAME_LENGTH - 1);
m_SourceName[E131_SOURCE_NAME_LENGTH - 1] = '\0';
#if (__GNUC__ > 8)
# pragma GCC diagnostic pop
#endif