summaryrefslogtreecommitdiffstats
path: root/src/simfs.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-10-13 02:38:11 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-10-13 05:04:47 -0500
commitbd8c7e92bbbcb467e410884e541e89c1638aa22e (patch)
tree93bf2f4e611aa84b45cb9607f69a1126213d47c9 /src/simfs.c
parente755292874995282ffdbcfed600fb3aec1c09425 (diff)
downloadofono-bd8c7e92bbbcb467e410884e541e89c1638aa22e.tar.bz2
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.
Diffstat (limited to 'src/simfs.c')
-rw-r--r--src/simfs.c9
1 files 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",