GCC 8.2 Warning in Testing

Folks,

The following warnings are present with the gcc 8.2 compiler. They
occur in the test cxx files.

Building CXX object
Common/Core/Testing/Cxx/CMakeFiles/vtkCommonCoreCxxTests.dir/vtkCommonCoreCxxTests.cxx.o
In function ‘char* lowercase(const char*)’,
inlined from ‘int main(int, char**)’ at
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:380:20:
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:332:10:
warning: ‘char* strncpy(char*, const char*, size_t)’ specified
bound depends on the length of the source argument
[-Wstringop-overflow=]
strncpy(new_string, string, stringSize);
~^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:
In function ‘int main(int, char**)’:
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:326:38:
note: length computed here
stringSize = CM_CAST(size_t, strlen(string) + 1);
^~
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:73:47:
note: in definition of macro ‘CM_CAST’
#define CM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)
^~~~
In function ‘char* lowercase(const char*)’,
inlined from ‘int main(int, char**)’ at
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:383:26:
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:332:10:
warning: ‘char* strncpy(char*, const char*, size_t)’ specified
bound depends on the length of the source argument
[-Wstringop-overflow=]
strncpy(new_string, string, stringSize);
~^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:
In function ‘int main(int, char**)’:
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:326:38:
note: length computed here
stringSize = CM_CAST(size_t, strlen(string) + 1);
^~
/home/lorensen/ProjectsGIT/VTKNewModules-linux/Common/Core/Testing/Cxx/vtkCommonCoreCxxTests.cxx:73:47:
note: in definition of macro ‘CM_CAST’
#define CM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)

This warning was fixed in cmake 3.11.3.

Two solutions:

  1. Require 3.11.3 or higher.
  2. Users can add -Wstringop-overflow=0 to CMAKE_CXX_FLAGS