From 6425dc55b720a0fd9c6d9d1a7fbe955670c74ce8 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Thu, 18 Jul 2019 22:24:26 +0200 Subject: [PATCH] Only move buffer when offset is not zero. --- coders/bytebuffer-private.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/coders/bytebuffer-private.h b/coders/bytebuffer-private.h index 38b5467ba..cc2bde863 100644 --- a/coders/bytebuffer-private.h +++ b/coders/bytebuffer-private.h @@ -42,7 +42,8 @@ static inline int ReadMagickByteBuffer(MagickByteBuffer *buffer) } if ((buffer->offset == 0) && (buffer->count == 0)) { - buffer->count=ReadBlob(buffer->image,sizeof(buffer->data)-1,buffer->data); + buffer->count=ReadBlob(buffer->image,sizeof(buffer->data)-1, + buffer->data); if (buffer->count < 1) return(EOF); } @@ -55,14 +56,17 @@ static inline char *GetMagickByteBufferDatum(MagickByteBuffer *buffer) count, i; - i=0; - while (buffer->offset < buffer->count) - buffer->data[i++]=buffer->data[buffer->offset++]; - count=ReadBlob(buffer->image,sizeof(buffer->data)-1-i,buffer->data+i); - buffer->count=i; - if (count > 0) - buffer->count+=count; - buffer->offset=0; + if (buffer->offset != 0) + { + i=0; + while (buffer->offset < buffer->count) + buffer->data[i++]=buffer->data[buffer->offset++]; + count=ReadBlob(buffer->image,sizeof(buffer->data)-1-i,buffer->data+i); + buffer->count=i; + if (count > 0) + buffer->count+=count; + buffer->offset=0; + } return((char *) buffer->data); } -- 2.40.0