我正在Linux上使用GCC 8.2.0并在Cygwin上使用GCC 8.1.0(后者是自动CI构建)编译一些C代码(如果确实需要,将提供链接)。
在Linux上,一切顺利。在Cygwin上,除其他外,我得到以下警告:
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);
^~~~~~~~~~~~~~
和
C:\Users\travis\build\eyalroz\ssb-dbgen\src\build.c:697:5: warning: 'strncpy' specified bound 10 equals destination size [-Wstringop-truncation]
strncpy(d->dayofweek, weekday_names[d->daynuminweek-1],D_DAYWEEK_LEN+1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\travis\build\eyalroz\ssb-dbgen\src\build.c:698:5: warning: 'strncpy' specified bound 10 equals destination size [-Wstringop-truncation]
strncpy(d->month,month_names[d->monthnuminyear-1],D_MONTH_LEN+1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
据我所知,我什么也没做,这两种情况下都会导致不同的编译标志。为什么我只能在一种环境中收到警告?可以是GCC版本吗?