From ac6f016748f58fc871cb93e337077b6b1942282a Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 14 Sep 2015 22:51:03 +0200 Subject: [PATCH] Fix partition reads and writes at end. --- kernel/partition.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/partition.cpp b/kernel/partition.cpp index 47323ea5..92894c0c 100644 --- a/kernel/partition.cpp +++ b/kernel/partition.cpp @@ -77,9 +77,7 @@ off_t Partition::lseek(ioctx_t* /*ctx*/, off_t offset, int whence) ssize_t Partition::pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off) { - // TODO: Avoid underflow and overflow! - off_t end_at = off + count; - if ( length <= end_at ) + if ( length <= off ) return 0; off_t available = length - off; if ( (uintmax_t) available < (uintmax_t) count ) @@ -90,9 +88,7 @@ ssize_t Partition::pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off) ssize_t Partition::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off) { - // TODO: Avoid underflow and overflow! - off_t end_at = off + count; - if ( length <= end_at ) + if ( length <= off ) return 0; off_t available = length - off; if ( (uintmax_t) available < (uintmax_t) count )