From bd8c7e92bbbcb467e410884e541e89c1638aa22e Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 13 Oct 2010 02:38:11 -0500 Subject: [PATCH] simfs: Fix the number of bytes copied In block reading operations we read too much when the number of bytes to read is smaller than the size of the file. --- src/simfs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/simfs.c b/src/simfs.c index fd92e50c..4a5570c0 100644 --- a/src/simfs.c +++ b/src/simfs.c @@ -227,12 +227,13 @@ static void sim_fs_op_read_block_cb(const struct ofono_error *error, if (op->current == start_block) { bufoff = 0; dataoff = op->offset % 256; - tocopy = MIN(256 - op->offset % 256, len); + tocopy = MIN(256 - op->offset % 256, + op->num_bytes - op->current * 256); } else { bufoff = (op->current - start_block - 1) * 256 + op->offset % 256; dataoff = 0; - tocopy = len; + tocopy = MIN(256, op->num_bytes - op->current * 256); } DBG("bufoff: %d, dataoff: %d, tocopy: %d", @@ -290,12 +291,12 @@ static gboolean sim_fs_op_read_block(gpointer user_data) seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256 + op->offset % 256; toread = MIN(256 - op->offset % 256, - op->length - op->current * 256); + op->num_bytes - op->current * 256); } else { bufoff = (op->current - start_block - 1) * 256 + op->offset % 256; seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256; - toread = MIN(256, op->length - op->current * 256); + toread = MIN(256, op->num_bytes - op->current * 256); } DBG("bufoff: %d, seekoff: %d, toread: %d",