const char* Status::CopyState(const char* state) { const size_t cch = std::strlen(state) + 1; // +1 for the null terminator char* const result = new char[cch]; result[cch - 1] = '\0'; #ifdef OS_WIN errno_t ret; ret = strncpy_s(result, cch, state, cch - 1); assert(ret == 0); #else std::strncpy(result, state, cch - 1); #endif return result; } error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] std::strncpy(result, state, cch); ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ status.cc:18:33: note: length computed here const size_t cch = std::strlen(state);
Please review https://gcc.gnu.org/bugs to see what information GCC bug reports are expected to include. This one contains none of the requested information. As far as I can see the warning message reflects the effect of the strncpy call in the function but the source code printed by the message doesn't correspond to the source code so it's not clear how the diagnostic messages are related to the code snippet, or even what it is you are trying to point out. Thus this is not a valid report. If you can provide the requested information and explain what you think is wrong with GCC's output feel free to reopen it.