Commit 837df8f7 authored by Kenton Varda's avatar Kenton Varda

Don't mmap empty files.

parent 9c3628b4
......@@ -62,6 +62,11 @@ kj::Array<const char> mmapForRead(kj::StringPtr filename) {
KJ_SYSCALL(fstat(fd, &stats));
if (S_ISREG(stats.st_mode)) {
if (stats.st_size == 0) {
// mmap()ing zero bytes will fail.
return nullptr;
}
// Regular file. Just mmap() it.
const void* mapping = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (mapping == MAP_FAILED) {
......
......@@ -351,6 +351,11 @@ kj::Array<const char> SchemaFile::DiskFileReader::read(kj::StringPtr path) const
KJ_SYSCALL(fstat(fd, &stats));
if (S_ISREG(stats.st_mode)) {
if (stats.st_size == 0) {
// mmap()ing zero bytes will fail.
return nullptr;
}
// Regular file. Just mmap() it.
const void* mapping = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (mapping == MAP_FAILED) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment