From fdf7e508f70bbf24adeb1beba2fc5ab825217f92 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 2 May 2010 01:24:55 +0000 Subject: wow, bug fixes everywhere. --- src/client.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 2ea72a2..95008f9 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -173,8 +173,14 @@ void Bu::Client::write( uint64_t nData ) sWriteBuf.append( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::read( void *pData, int nBytes ) +int Bu::Client::read( void *pData, int nBytes ) { + if( nBytes > sReadBuf.getSize()-nRBOffset ) + { + nBytes = sReadBuf.getSize()-nRBOffset; + if( nBytes <= 0 ) + return 0; + } memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); nRBOffset += nBytes; if( sReadBuf.getSize()-nRBOffset == 0 ) @@ -192,11 +198,20 @@ void Bu::Client::read( void *pData, int nBytes ) sReadBuf.trimFront( nRBOffset ); nRBOffset = 0; } + + return nBytes; } -void Bu::Client::peek( void *pData, int nBytes, int nOffset ) +int Bu::Client::peek( void *pData, int nBytes, int nOffset ) { + if( nBytes+nOffset > sReadBuf.getSize()-nRBOffset ) + { + nBytes = sReadBuf.getSize()-nRBOffset-nOffset; + if( nBytes <= 0 ) + return 0; + } memcpy( pData, sReadBuf.getStr()+nRBOffset+nOffset, nBytes ); + return nBytes; } void Bu::Client::seek( int nBytes ) -- cgit v1.2.3