A better fix

上级 286cbb04
...@@ -138,21 +138,20 @@ vmnode::loadpg(off_t off) ...@@ -138,21 +138,20 @@ vmnode::loadpg(off_t off)
mtwriteavar("vmnode:%016x", this); mtwriteavar("vmnode:%016x", this);
#endif #endif
char *p = page[off/PGSIZE]; char *p = page[off/PGSIZE];
s64 n;
if (sz - off < PGSIZE) s64 n = sz-off < PGSIZE ? sz-off : PGSIZE;
n = sz - off; off += offset;
else s64 filen = off > ip->size ? 0 : MIN(n, ip->size-off);
n = PGSIZE;
// //
// Possible race condition with concurrent loadpg() calls, // Possible race condition with concurrent loadpg() calls,
// if the underlying inode's contents change.. // if the underlying inode's contents change..
// //
if (readi(ip, p, offset+off, n) != n) if (readi(ip, p, off, filen) != filen)
return -1; return -1;
// XXX(sbw) we might leave the begining of page[0] and the // XXX(sbw) if we call vmnode::loadpg once for each page,
// end of page[npages-1] with some random content. // then we should memset(&p[filen], 0, n-filen)
return 0; return 0;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论