diff --git a/src/zm_buffer.cpp b/src/zm_buffer.cpp index 73c9603e1..be20c008e 100644 --- a/src/zm_buffer.cpp +++ b/src/zm_buffer.cpp @@ -17,62 +17,51 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include - #include "zm.h" #include "zm_buffer.h" -unsigned int Buffer::assign( const unsigned char *pStorage, unsigned int pSize ) -{ - if ( mAllocation < pSize ) - { +unsigned int Buffer::assign(const unsigned char *pStorage, unsigned int pSize) { + if ( mAllocation < pSize ) { delete[] mStorage; mAllocation = pSize; mHead = mStorage = new unsigned char[pSize]; } mSize = pSize; - memcpy( mStorage, pStorage, mSize ); + memcpy(mStorage, pStorage, mSize); mHead = mStorage; mTail = mHead + mSize; - return( mSize ); + return mSize; } -unsigned int Buffer::expand( unsigned int count ) -{ +unsigned int Buffer::expand(unsigned int count) { int spare = mAllocation - mSize; int headSpace = mHead - mStorage; int tailSpace = spare - headSpace; int width = mTail - mHead; - if ( spare > (int)count ) - { - if ( tailSpace < (int)count ) - { - memmove( mStorage, mHead, mSize ); + if ( spare > static_castcount ) { + if ( tailSpace < static_castcount ) { + memmove(mStorage, mHead, mSize); mHead = mStorage; mTail = mHead + width; } - } - else - { + } else { mAllocation += count; unsigned char *newStorage = new unsigned char[mAllocation]; - if ( mStorage ) - { - memcpy( newStorage, mHead, mSize ); + if ( mStorage ) { + memcpy(newStorage, mHead, mSize); delete[] mStorage; } mStorage = newStorage; mHead = mStorage; mTail = mHead + width; } - return( mSize ); + return mSize; } -int Buffer::read_into( int sd, unsigned int bytes ) { +int Buffer::read_into(int sd, unsigned int bytes) { // Make sure there is enough space this->expand(bytes); - int bytes_read = read( sd, mTail, bytes ); + int bytes_read = read(sd, mTail, bytes); if ( bytes_read > 0 ) { mTail += bytes_read; mSize += bytes_read;