Skip to content

Commit

Permalink
engine: net_chan: check BZ2 functions return value and log if it's no…
Browse files Browse the repository at this point in the history
…t BZ_OK
  • Loading branch information
a1batross committed Nov 28, 2024
1 parent 8885996 commit df4194c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions engine/common/net_chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
byte pbOut[0x10000];
uint uSourceSize = MSG_GetNumBytesWritten( msg );
uint uCompressedSize = MSG_GetNumBytesWritten( msg ) - 4;
if( !BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), uSourceSize, 9, 0, 30 ))
if( BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), uSourceSize, 9, 0, 30 ) == BZ_OK )
{
if( uCompressedSize < uSourceSize )
{
Expand Down Expand Up @@ -1180,12 +1180,20 @@ qboolean Netchan_CopyNormalFragments( netchan_t *chan, sizebuf_t *msg, size_t *l
#if !XASH_DEDICATED
byte buf[0x10000];
uint uDecompressedLen = sizeof( buf );
int bz2_err = BZ2_bzBuffToBuffDecompress( buf, &uDecompressedLen, MSG_GetData( msg ) + 4, MSG_GetNumBytesWritten( msg ) - 4, 1, 0 );

BZ2_bzBuffToBuffDecompress( buf, &uDecompressedLen, MSG_GetData( msg ) + 4, MSG_GetNumBytesWritten( msg ) - 4, 1, 0 );
memcpy( msg->pData, buf, uDecompressedLen );
size = uDecompressedLen;
if( bz2_err == BZ_OK )
{
size = uDecompressedLen;
memcpy( msg->pData, buf, size );
}
else
{
Con_Printf( S_ERROR "%s: BZ2 decompression failed (%d)\n", __func__, bz2_err );
return false;
}
#else
Host_Error( "%s: BZ2 compression is not supported for server", __func__ );
Host_Error( "%s: BZ2 compression is not supported for server\n", __func__ );
#endif
}
else if( !chan->use_bz2 && LZSS_IsCompressed( MSG_GetData( msg ), size ))
Expand Down

0 comments on commit df4194c

Please sign in to comment.