ProcFS: Check for empty Optional in read_bytes()

In read_bytes() we now check that the Optional "data" actually
contains a value before use, avoiding a failing asserting in
kernel space.
This commit is contained in:
Drew Stratford 2019-10-22 22:45:48 +13:00 committed by Andreas Kling
parent 4d99856f95
commit d063734f69
Notes: sideshowbarker 2024-07-19 11:34:50 +09:00

View File

@ -997,10 +997,14 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
}
auto& data = generated_data;
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
memcpy(buffer, data.value().data() + offset, nread);
if (nread == 0 && description && description->generator_cache())
description->generator_cache().clear();
ssize_t nread = 0;
if (data.has_value()) {
nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
memcpy(buffer, data.value().data() + offset, nread);
if (nread == 0 && description && description->generator_cache())
description->generator_cache().clear();
}
return nread;
}