summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2013-03-13 21:36:05 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2013-03-13 21:36:05 (GMT)
commitda5cec5613dbb4673425043310e617698e06f53a (patch)
tree522b2aa27a433fe5deccde7c3e59ceb9baa2cf2c
parent1ef631e23888a0356387c4cd5cf4730c4a2fa8fa (diff)
downloadlibrosprite-da5cec5613dbb4673425043310e617698e06f53a.tar.gz
librosprite-da5cec5613dbb4673425043310e617698e06f53a.tar.bz2
make rosprite_mem_reader() better.
-rw-r--r--src/librosprite.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/librosprite.c b/src/librosprite.c
index 9252510..b382ce0 100644
--- a/src/librosprite.c
+++ b/src/librosprite.c
@@ -368,19 +368,18 @@ void rosprite_destroy_mem_context(struct rosprite_mem_context* ctx)
int rosprite_mem_reader(uint8_t* buf, size_t count, void* ctx)
{
size_t copy_size;
- struct rosprite_mem_context* memctx = (struct rosprite_mem_context*) ctx;
- if (memctx->offset + count > memctx->size) {
- return -1;
- }
+ struct rosprite_mem_context* memctx = ctx;
- // if we're asked for more memory than the block contains, only copy as much as we can
+ /* if we're asked for more memory than the block contains,
+ * only copy as much as we can
+ */
if ((memctx->offset + count) > memctx->size) {
copy_size = memctx->size - memctx->offset;
} else {
copy_size = count;
}
- memcpy(buf, memctx->base + memctx->offset, count);
- memctx->offset += count;
+ memcpy(buf, memctx->base + memctx->offset, copy_size);
+ memctx->offset += copy_size;
return copy_size;
}