Skip to content

Commit e240d59

Browse files
committed
reaper/TreeWatch: do not null-terminate buffer in IsPopulated(), construct std::string_view
1 parent c1ef0d9 commit e240d59

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/reaper/UnifiedWatch.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ static bool
2424
IsPopulated(FileDescriptor fd) noexcept
2525
{
2626
char buffer[4096];
27-
ssize_t nbytes = pread(fd.Get(), buffer, sizeof(buffer) - 1, 0);
27+
ssize_t nbytes = pread(fd.Get(), buffer, sizeof(buffer), 0);
2828
if (nbytes <= 0)
2929
return false;
3030

31-
buffer[nbytes] = 0;
32-
return strstr(buffer, "populated 0") == nullptr;
31+
const std::string_view contents{buffer, static_cast<std::size_t>(nbytes)};
32+
return !contents.contains("populated 0"sv);
3333
}
3434

3535
class UnifiedCgroupWatch::Group {

0 commit comments

Comments
 (0)