I have code which looks like this:
char* newChar = new char[strlen(inputCharArray)+1];
if (NULL == newChar) {
return;
}
strncpy(newChar, inputCharArray, strlen(inputCharArray));
newChar[strlen(inputCharArray)] = '\0';
This seems for me like totally valid code. But GCC 9.2.1 is complaining about it, with the following warning:
warning: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Wstringop-overflow=]