GCC warning re string truncation
Closed this issue · 1 comments
seghcder commented
Currently using GCC10 on Fedora32, however I believe this warning was added in GCC8
In member function ‘void io::error::with_file_name::set_file_name(const char*)’,
inlined from ‘char* io::LineReader::next_line()’ at /home/user/app/thingbase/ext/csv.hpp:472:34,
inlined from ‘bool io::CSVReader<column_count, trim_policy, quote_policy, overflow_policy, comment_policy>::read_row(ColType& ...) [with ColType = {char*, char*, char*, char*, char*, char*, char*, char*}; unsigned int column_count = 8; trim_policy = io::trim_chars<'\011'>; quote_policy = io::double_quote_escape<',', '\"'>; overflow_policy = io::throw_on_overflow; comment_policy = io::no_comment]’ at /home/user/app/thingbase/ext/csv.hpp:1245:44,
inlined from ‘virtual void xtemplate::XTrader::Initialize()’ at /home/user/app/thingbase/src/templates/XTrader.cpp:87:22:
/home/user/app/thingbase/ext/csv.hpp:78:28: warning: ‘char* strncpy(char*, const char*, size_t)’ output may be truncated copying 255 bytes from a string of length 255 [-Wstringop-truncation]
78 | strncpy(this->file_name, file_name, sizeof(this->file_name));
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nothing critical - still compiling and working it seems.
Full version gcc version 10.2.1 20200723 (Red Hat 10.2.1-1) (GCC)
Thanks!
ben-strasser commented
In theory, GCC should detect the 0-assignment in the next line and silence the warning. However, this part of GCC seems to be buggy and not always sees the 0-assignment.
Related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87028
Adding superfluous parenthesis suppresses the warning. I added that.