fix write buffer alignment if the write buffer is empty and
misaligned; the m_iWriteBufferUsed == 0 case would skip the realignment
This commit is contained in:
@@ -204,6 +204,8 @@ int RageFileObj::EmptyWriteBuf()
|
|||||||
if( m_pWriteBuffer == NULL )
|
if( m_pWriteBuffer == NULL )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if( m_iWriteBufferUsed )
|
||||||
|
{
|
||||||
/* The write buffer may not align with the actual file, if we've seeked. Only
|
/* The write buffer may not align with the actual file, if we've seeked. Only
|
||||||
* seek if needed. */
|
* seek if needed. */
|
||||||
bool bSeeked = (m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos);
|
bool bSeeked = (m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos);
|
||||||
@@ -216,6 +218,7 @@ int RageFileObj::EmptyWriteBuf()
|
|||||||
SeekInternal( m_iFilePos );
|
SeekInternal( m_iFilePos );
|
||||||
if( iRet == -1 )
|
if( iRet == -1 )
|
||||||
return iRet;
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
m_iWriteBufferPos = m_iFilePos;
|
m_iWriteBufferPos = m_iFilePos;
|
||||||
m_iWriteBufferUsed = 0;
|
m_iWriteBufferUsed = 0;
|
||||||
@@ -228,15 +231,12 @@ int RageFileObj::Write( const void *pBuffer, size_t iBytes )
|
|||||||
{
|
{
|
||||||
/* If the file position has moved away from the write buffer, or the
|
/* If the file position has moved away from the write buffer, or the
|
||||||
* incoming data won't fit in the buffer, flush. */
|
* incoming data won't fit in the buffer, flush. */
|
||||||
if( m_iWriteBufferUsed )
|
|
||||||
{
|
|
||||||
if( m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos || m_iWriteBufferUsed + (int)iBytes > m_iWriteBufferSize )
|
if( m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos || m_iWriteBufferUsed + (int)iBytes > m_iWriteBufferSize )
|
||||||
{
|
{
|
||||||
int iRet = EmptyWriteBuf();
|
int iRet = EmptyWriteBuf();
|
||||||
if( iRet == -1 )
|
if( iRet == -1 )
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( m_iWriteBufferUsed + (int)iBytes <= m_iWriteBufferSize )
|
if( m_iWriteBufferUsed + (int)iBytes <= m_iWriteBufferSize )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user