Windows+MinGW build fails with "warning: 'strncpy' output truncated before terminating nul"
eyalroz opened this issue · comments
Eyal Rozenberg commented
The Travis CI build with Windows, MinGW and GCC 8.1.0, gives us several warnings (and we consider warnings as errors), including the following:
C:\Users\travis\build\eyalroz\ssb-dbgen\src\bm_utils.c: In function 'e_str':
C:\Users\travis\build\eyalroz\ssb-dbgen\src\bm_utils.c:199:5: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy(dest + loc, strtmp, len);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\travis\build\eyalroz\ssb-dbgen\src\bm_utils.c:197:11: note: length computed here
len = strlen(strtmp);
^~~~~~~~~~~~~~
This is actually due to new capabilities of GCC 8 (this build uses gcc 8.1.0): String truncation detection. Good on them! ... however, we do some "planting" of strings within other, existing strings, which triggers a false positive of that detection. Let's make such copying use memcpy()
, since we know exactly how much copying to do.