From da5cec5613dbb4673425043310e617698e06f53a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 13 Mar 2013 21:36:05 +0000 Subject: make rosprite_mem_reader() better. --- src/librosprite.c | 13 ++++++------- 1 file 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; } -- cgit v1.2.3