Fix asserts with side-effects (per Keegan McAllister)

This commit is contained in:
Keith Winstein
2012-03-08 10:50:19 -05:00
parent 4a29ab9d70
commit df5d163f9c
15 changed files with 80 additions and 35 deletions
+7 -7
View File
@@ -1,7 +1,7 @@
#include <zlib.h>
#include <assert.h>
#include "compressor.h"
#include "dos_assert.h"
using namespace Network;
using namespace std;
@@ -9,18 +9,18 @@ using namespace std;
string Compressor::compress_str( const string input )
{
long unsigned int len = BUFFER_SIZE;
assert( Z_OK == compress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
dos_assert( Z_OK == compress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
}
string Compressor::uncompress_str( const string input )
{
long unsigned int len = BUFFER_SIZE;
assert( Z_OK == uncompress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
dos_assert( Z_OK == uncompress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
}
+3 -2
View File
@@ -22,6 +22,7 @@
#include "transportfragment.h"
#include "transportinstruction.pb.h"
#include "compressor.h"
#include "fatal_assert.h"
using namespace Network;
using namespace TransportBuffers;
@@ -46,7 +47,7 @@ string Fragment::tostring( void )
ret += network_order_string( id );
assert( !( fragment_num & 0x8000 ) ); /* effective limit on size of a terminal screen change or buffered user input */
fatal_assert( !( fragment_num & 0x8000 ) ); /* effective limit on size of a terminal screen change or buffered user input */
uint16_t combined_fragment_num = ( final << 15 ) | fragment_num;
ret += network_order_string( combined_fragment_num );
@@ -122,7 +123,7 @@ Instruction FragmentAssembly::get_assembly( void )
}
Instruction ret;
assert( ret.ParseFromString( get_compressor().uncompress_str( encoded ) ) );
fatal_assert( ret.ParseFromString( get_compressor().uncompress_str( encoded ) ) );
fragments.clear();
fragments_arrived = 0;