[llvm-cov gcov] Don't require NUL terminator when reading files
authorFangrui Song <i@maskray.me>
Sun, 19 Jul 2020 07:26:01 +0000 (00:26 -0700)
committerFangrui Song <i@maskray.me>
Sun, 19 Jul 2020 07:31:52 +0000 (00:31 -0700)
commit2e74b6d80f347203ae17ec8b09e6b3e86ff6c179
tree4e1504747005299f66271953179be92865e5d4eb
parentd37befdfe5cd93666f8077c32836673ad70385d1
[llvm-cov gcov] Don't require NUL terminator when reading files

.gcno, .gcda and source files can be modified while we are reading them. If the
concurrent modification of a file being read nullifies the NUL terminator
assumption, llvm-cov can trip over an assertion failure in MemoryBuffer::init.
This is not so rare - the source files can be in an editor and .gcda can be
written by an running process (if the process forks, when .gcda gets written is
probably more unpredictable).

There is no accompanying test because an assertion failure requires data
races with some involved setting.
llvm/lib/ProfileData/GCOV.cpp
llvm/tools/llvm-cov/gcov.cpp