From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 3/4] simfs: fix incorrect math when calculating length to copy
Date: Mon, 04 Oct 2010 15:33:21 -0700 [thread overview]
Message-ID: <1286231602-18692-4-git-send-email-kristen@linux.intel.com> (raw)
In-Reply-To: <1286231602-18692-1-git-send-email-kristen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 1525 bytes --]
---
src/simfs.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/simfs.c b/src/simfs.c
index 5fbee8b..bfcdf23 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -229,14 +229,16 @@ 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);
} else {
- bufoff = (op->current - start_block - 1) * 256 +
- op->offset % 256;
+ bufoff = op->current * 256;
dataoff = 0;
- tocopy = len;
}
+ tocopy = op->num_bytes % 256;
+
+ if ((tocopy == 0) || (op->current != end_block))
+ tocopy = 256;
+
memcpy(fs->buffer + bufoff, data + dataoff, tocopy);
cache_block(fs, op->current, 256, data, len);
@@ -288,15 +290,16 @@ static gboolean sim_fs_op_read_block(gpointer user_data)
bufoff = 0;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256 +
op->offset % 256;
- toread = MIN(256 - op->offset % 256,
- op->length - op->current * 256);
} else {
- bufoff = (op->current - start_block - 1) * 256 +
- op->offset % 256;
+ bufoff = op->current * 256;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256;
- toread = MIN(256, op->length - op->current * 256);
}
+ toread = op->num_bytes % 256;
+
+ if ((toread == 0) || (op->current != end_block))
+ toread = 256;
+
if (lseek(fs->fd, seekoff, SEEK_SET) == (off_t) -1)
break;
--
1.7.2.1
next prev parent reply other threads:[~2010-10-04 22:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-04 22:33 [PATCH 0/4] Icon patches (rebased) Kristen Carlson Accardi
2010-10-04 22:33 ` [PATCH 1/4] simfs: cache images Kristen Carlson Accardi
2010-10-12 1:16 ` Denis Kenzior
2010-10-04 22:33 ` [PATCH 2/4] sim: implement GetIcon Kristen Carlson Accardi
2010-10-13 13:44 ` Denis Kenzior
2010-10-04 22:33 ` Kristen Carlson Accardi [this message]
2010-10-13 13:44 ` [PATCH 3/4] simfs: fix incorrect math when calculating length to copy Denis Kenzior
2010-10-14 18:18 ` [PATCH] simfs: fix incorrect math again Kristen Carlson Accardi
2010-11-02 14:41 ` Kristen Carlson Accardi
2010-11-02 14:57 ` Denis Kenzior
2010-11-29 19:13 ` [PATCH] simfs: make sim_fs_read_block work for > 256 byte files Kristen Carlson Accardi
2010-10-04 22:33 ` [PATCH 4/4] simutil: add file type for EFimg Kristen Carlson Accardi
2010-10-12 3:16 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1286231602-18692-4-git-send-email-kristen@linux.intel.com \
--to=kristen@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox