mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
bug fix: reset stack data stream before getting length and writing. Assert
so easier to catch similar problems.
This commit is contained in:
parent
29c8b461b8
commit
9c06582029
2 changed files with 18 additions and 3 deletions
|
@ -143,6 +143,7 @@ getOneBit( MemStreamCtxt* stream )
|
|||
if ( stream->nReadBits == 0 ) {
|
||||
++stream->curReadPos;
|
||||
}
|
||||
XP_ASSERT( stream->curReadPos <= stream->nBytesWritten );
|
||||
|
||||
rack = stream->buf[stream->curReadPos-1];
|
||||
mask = 1 << stream->nReadBits++;
|
||||
|
|
|
@ -110,7 +110,16 @@ stack_loadFromStream( StackCtxt* stack, XWStreamCtxt* stream )
|
|||
void
|
||||
stack_writeToStream( StackCtxt* stack, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 nBytes = !!stack->data? stream_getSize( stack->data ): 0;
|
||||
XP_U16 nBytes;
|
||||
XWStreamCtxt* data = stack->data;
|
||||
XWStreamPos oldPos = START_OF_STREAM;
|
||||
|
||||
if ( !!data ) {
|
||||
oldPos = stream_setPos( data, START_OF_STREAM, POS_READ );
|
||||
nBytes = stream_getSize( data );
|
||||
} else {
|
||||
nBytes = 0;
|
||||
}
|
||||
|
||||
stream_putU16( stream, nBytes );
|
||||
|
||||
|
@ -119,8 +128,13 @@ stack_writeToStream( StackCtxt* stack, XWStreamCtxt* stream )
|
|||
stream_putU16( stream, stack->nEntries );
|
||||
stream_putU32( stream, stack->top );
|
||||
|
||||
stream_setPos( stack->data, START_OF_STREAM, POS_READ );
|
||||
stream_copyFromStream( stream, stack->data, nBytes );
|
||||
stream_setPos( data, START_OF_STREAM, POS_READ );
|
||||
stream_copyFromStream( stream, data, nBytes );
|
||||
}
|
||||
|
||||
if ( !!data ) {
|
||||
/* in case it'll be used further */
|
||||
(void)stream_setPos( data, oldPos, POS_READ );
|
||||
}
|
||||
} /* stack_writeToStream */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue