summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-02-17 19:46:33 +1030
committerRusty Russell <rusty@rustcorp.com.au>2009-02-17 19:46:33 +1030
commitf5129b0c08976fbaa07d3d610de40677e81ad344 (patch)
tree56ffab44c1c1c52ab09848fff92815fb0e9ea668
parent5b9275d0ffb22530a6942c068bef9ba90d41b8f4 (diff)
Slight cleanup for crcsync.c
-rw-r--r--ccan/crcsync/crcsync.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ccan/crcsync/crcsync.c b/ccan/crcsync/crcsync.c
index cb768806..6c251f1f 100644
--- a/ccan/crcsync/crcsync.c
+++ b/ccan/crcsync/crcsync.c
@@ -170,10 +170,6 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
/* Make sure we have a copy of the last block_size bytes.
* First, copy down the old data. */
if (buffer_size(ctx)) {
- memmove(ctx->buffer, ctx->buffer + ctx->buffer_start,
- buffer_size(ctx));
- ctx->buffer_end -= ctx->buffer_start;
- ctx->buffer_start = 0;
}
if (crcmatch >= 0) {
@@ -202,6 +198,14 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
/* Now save any literal bytes we'll need in future. */
len = ctx->literal_bytes - buffer_size(ctx);
+
+ /* Move down old data if we don't have room. */
+ if (ctx->buffer_end + len > ctx->block_size) {
+ memmove(ctx->buffer, ctx->buffer + ctx->buffer_start,
+ buffer_size(ctx));
+ ctx->buffer_end -= ctx->buffer_start;
+ ctx->buffer_start = 0;
+ }
memcpy(ctx->buffer + ctx->buffer_end, buf, len);
ctx->buffer_end += len;
assert(buffer_size(ctx) <= ctx->block_size);