read format spec outside assert

since the read inside goes away in release builds!
This commit is contained in:
Eric House 2018-07-13 06:59:57 -07:00
parent b8c2cd1dd5
commit c45c9cd809

View file

@ -34,6 +34,8 @@
# define SMS_PROTO_VERSION 1 # define SMS_PROTO_VERSION 1
# define SMS_PROTO_VERSION_COMBO 2 # define SMS_PROTO_VERSION_COMBO 2
# define PARTIALS_FORMAT 0
typedef struct _MsgRec { typedef struct _MsgRec {
XP_U32 createSeconds; XP_U32 createSeconds;
SMSMsg msg; SMSMsg msg;
@ -427,8 +429,6 @@ addMessage( SMSProto* state, const XP_UCHAR* fromPhone, int msgID, int indx,
if ( msgIDRec->count == 0 ) { if ( msgIDRec->count == 0 ) {
msgIDRec->count = count; /* in case it's new */ msgIDRec->count = count; /* in case it's new */
msgIDRec->parts = XP_CALLOC( state->mpool, count * sizeof(*msgIDRec->parts)); msgIDRec->parts = XP_CALLOC( state->mpool, count * sizeof(*msgIDRec->parts));
} else {
XP_ASSERT( count == msgIDRec->count );
} }
XP_ASSERT( msgIDRec->parts[indx].len == 0 XP_ASSERT( msgIDRec->parts[indx].len == 0
@ -495,7 +495,7 @@ savePartials( SMSProto* state )
XWStreamCtxt* stream XWStreamCtxt* stream
= mem_stream_make_raw( MPPARM(state->mpool) = mem_stream_make_raw( MPPARM(state->mpool)
dutil_getVTManager(state->dutil) ); dutil_getVTManager(state->dutil) );
stream_putU8( stream, 0 ); /* version */ stream_putU8( stream, PARTIALS_FORMAT );
stream_putU8( stream, state->nFromPhones ); stream_putU8( stream, state->nFromPhones );
for ( int ii = 0; ii < state->nFromPhones; ++ii ) { for ( int ii = 0; ii < state->nFromPhones; ++ii ) {
@ -532,12 +532,11 @@ savePartials( SMSProto* state )
static void static void
restorePartials( SMSProto* state ) restorePartials( SMSProto* state )
{ {
// LOG_FUNC();
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(state->mpool) XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(state->mpool)
dutil_getVTManager(state->dutil) ); dutil_getVTManager(state->dutil) );
dutil_loadStream( state->dutil, KEY_PARTIALS, stream ); dutil_loadStream( state->dutil, KEY_PARTIALS, stream );
if ( stream_getSize( stream ) >= 1 ) { if ( stream_getSize( stream ) >= 1
XP_ASSERT( 0 == stream_getU8( stream ) ); && PARTIALS_FORMAT == stream_getU8( stream ) ) {
int nFromPhones = stream_getU8( stream ); int nFromPhones = stream_getU8( stream );
for ( int ii = 0; ii < nFromPhones; ++ii ) { for ( int ii = 0; ii < nFromPhones; ++ii ) {
XP_UCHAR phone[32]; XP_UCHAR phone[32];
@ -561,8 +560,6 @@ restorePartials( SMSProto* state )
} }
} }
stream_destroy( stream ); stream_destroy( stream );
// LOG_RETURN_VOID();
} }
static SMSMsgArray* static SMSMsgArray*