‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length

错误信息:

In function ‘AllocString’,
    inlined from ‘SetData’ at /home/yeqiang/Downloads/openjdk-jdk-14-23/src/java.desktop/share/native/liblcms/cmscgats.c:1586:47,
    inlined from ‘cmsIT8SetDataRowCol’ at /home/yeqiang/Downloads/openjdk-jdk-14-23/src/java.desktop/share/native/liblcms/cmscgats.c:2613:12:
/home/yeqiang/Downloads/openjdk-jdk-14-23/src/java.desktop/share/native/liblcms/cmscgats.c:1146:14: error: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
 1146 |     if (ptr) strncpy (ptr, str, Size-1);
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/yeqiang/Downloads/openjdk-jdk-14-23/src/java.desktop/share/native/liblcms/cmscgats.c: In function ‘cmsIT8SetDataRowCol’:
/home/yeqiang/Downloads/openjdk-jdk-14-23/src/java.desktop/share/native/liblcms/cmscgats.c:1141:46: note: length computed here
 1141 |     cmsUInt32Number Size = (cmsUInt32Number) strlen(str)+1;
      |                                              ^~~~~~~~~~~

添加gcc编译参数 -Wno-stringop-truncation

 

已标记关键词 清除标记
相关推荐
<div><pre><code> mkdir -p build cmake -Bbuild -H. -G Ninja -DCMAKE_INSTALL_PREFIX= -- The C compiler identification is GNU 8.2.0 -- The CXX compiler identification is GNU 8.2.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found PythonInterp: /usr/bin/python (found version "2.7.15") -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") -- Found PNG: /usr/lib/x86_64-linux-gnu/libpng.so (found version "1.6.34") -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.4") -- Configuring done -- Generating done ninja -C build ninja: Entering directory `build' [104/537] Building CXX object Libraries/libcar/CMakeFiles/car.dir/Sources/Rendition.cpp.o FAILED: Libraries/libcar/CMakeFiles/car.dir/Sources/Rendition.cpp.o /usr/bin/c++ -Dcar_EXPORTS -I../Libraries/libcar/Headers -I../Libraries/ext/Headers -I../Libraries/libbom/Headers -I../Libraries/libutil/Headers -std=c++11 -fno-rtti -fno-exceptions -fPIC -Wall -Werror -Wno-multichar -Wno-sign-compare -fdiagnostics-color -MD -MT Libraries/libcar/CMakeFiles/car.dir/Sources/Rendition.cpp.o -MF Libraries/libcar/CMakeFiles/car.dir/Sources/Rendition.cpp.o.d -o Libraries/libcar/CMakeFiles/car.dir/Sources/Rendition.cpp.o -c ../Libraries/libcar/Sources/Rendition.cpp ../Libraries/libcar/Sources/Rendition.cpp: In member function ‘std::vector<unsigned char> car::Rendition::write() const’: ../Libraries/libcar/Sources/Rendition.cpp:532:12: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(header.magic, "ISTC", 4); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ ../Libraries/libcar/Sources/Rendition.cpp:679:16: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(raw_header.magic, "DWAR", 4); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors [106/537] Building CXX object Libraries/libcar/CMakeFiles/car.dir/Sources/Writer.cpp.o FAILED: Libraries/libcar/CMakeFiles/car.dir/Sources/Writer.cpp.o /usr/bin/c++ -Dcar_EXPORTS -I../Libraries/libcar/Headers -I../Libraries/ext/Headers -I../Libraries/libbom/Headers -I../Libraries/libutil/Headers -std=c++11 -fno-rtti -fno-exceptions -fPIC -Wall -Werror -Wno-multichar -Wno-sign-compare -fdiagnostics-color -MD -MT Libraries/libcar/CMakeFiles/car.dir/Sources/Writer.cpp.o -MF Libraries/libcar/CMakeFiles/car.dir/Sources/Writer.cpp.o.d -o Libraries/libcar/CMakeFiles/car.dir/Sources/Writer.cpp.o -c ../Libraries/libcar/Sources/Writer.cpp ../Libraries/libcar/Sources/Writer.cpp: In member function ‘void car::Writer::write() const’: ../Libraries/libcar/Sources/Writer.cpp:101:12: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(header->magic, "RATC", 4); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ ../Libraries/libcar/Sources/Writer.cpp:131:14: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(keyfmt->magic, "tmfk", 4); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors [109/537] Building CXX object Libraries/libcar/CMakeFiles/test_car_Rendition.dir/Tests/test_Rendition.cpp.o ninja: build stopped: subcommand failed. make: *** [Makefile:22: all] Error 1 </unsigned></code></pre><p>该提问来源于开源项目:facebook/xcbuild</p></div>
<div><pre><code> readstat/readstat_writer.c:82:9: warning: ‘strncpyoutput truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] readstat/readstat_writer.c:261:5: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation] readstat/readstat_writer.c:316:9: warning: ‘strncpyoutput truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] readstat/sas/readstat_sas7bcat_write.c:108:5: warning: ‘strncpyoutput may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation] readstat/sas/readstat_sas.c:284:5: warning: ‘strncpyoutput may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation] readstat/sas/readstat_sas.c:337:5: warning: ‘strncpyoutput may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation] readstat/spss/readstat_sav_write.c:150:5: warning: ‘strncpyoutput may be truncated copying 9 bytes from a string of length 9 [-Wstringop-truncation] readstat/spss/readstat_sav_write.c:158:5: warning: ‘strncpyoutput may be truncated copying 8 bytes from a string of length 8 [-Wstringop-truncation] readstat/spss/readstat_por_write.c:194:5: warning: ‘strncpyoutput truncated before terminating nul copying 20 bytes from a string of the same length [-Wstringop-truncation] </code></pre><p>该提问来源于开源项目:WizardMac/ReadStat</p></div>
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页