From a60451d84c7d9c79730f00822af0c877be8a6fed Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 3 Dec 2024 21:06:36 -0800 Subject: [PATCH] tweak logging around message parsing where crash seems to be --- xwords4/common/device.c | 15 +++++++++------ xwords4/common/strutils.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/xwords4/common/device.c b/xwords4/common/device.c index 4761ca038..77fa1427d 100644 --- a/xwords4/common/device.c +++ b/xwords4/common/device.c @@ -536,17 +536,22 @@ dvc_makeMQTTNoSuchGames( XW_DUtilCtxt* dutil, XWEnv xwe, } static XP_Bool -isDevMsg( const MQTTDevID* myID, const XP_UCHAR* topic, XP_U32* gameID ) +isDevMsg( const MQTTDevID* myID, const XP_UCHAR* topic, XP_U32* gameIDP ) { XP_UCHAR buf[64]; formatMQTTDevTopic( myID, buf, VSIZE(buf) ); size_t topicLen = XP_STRLEN(buf); + XP_ASSERT( topicLen < VSIZE(buf)-1 ); + /* Does topic match xw4/device/ at least */ XP_Bool success = 0 == strncmp( buf, topic, topicLen ); if ( success ) { + /* Now get the gameID if it's there */ const XP_UCHAR* gameIDPart = topic + topicLen; - sscanf( gameIDPart, "/%X", gameID ); + int count = + sscanf( gameIDPart, "/%X", gameIDP ); + XP_ASSERT( 1 == count || 0 == *gameIDP ); /* firing */ } - // XP_LOGFF( "(%s) => %s (gameID=%X)", topic, boolToStr(success), *gameID ); + XP_LOGFF( "(%s) => %s (gameID=%X)", topic, boolToStr(success), *gameIDP ); return success; } @@ -659,11 +664,10 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic, MQTTDevID myID; dvc_getMQTTDevID( dutil, xwe, &myID ); - XP_LOGFF( "got myID" ); + // XP_LOGFF( "got myID" ); /* gets here */ XP_U32 gameID = 0; if ( isDevMsg( &myID, topic, &gameID ) ) { - XP_LOGFF( "is msg; gameID: %X", gameID ); XWStreamCtxt* stream = mkStream( dutil ); stream_putBytes( stream, buf, len ); @@ -722,7 +726,6 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic, } stream_destroy( stream ); } else if ( isCtrlMsg( &myID, topic ) ) { - XP_LOGFF( "is ctrl msg" ); dutil_onCtrlReceived( dutil, xwe, buf, len ); } else { XP_LOGFF( "OTHER" ); diff --git a/xwords4/common/strutils.c b/xwords4/common/strutils.c index 72a7f8a4e..7acf48565 100644 --- a/xwords4/common/strutils.c +++ b/xwords4/common/strutils.c @@ -666,14 +666,24 @@ smsToBin( XP_U8* out, XP_U16* outlenp, const XP_UCHAR* sms, XP_U16 smslen ) XP_UCHAR* formatMQTTDevID( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen ) { - XP_SNPRINTF( buf, bufLen, MQTTDevID_FMT, *devid ); + XP_ASSERT( bufLen >= 17 ); +#ifdef DEBUG + int len = +#endif + XP_SNPRINTF( buf, bufLen, MQTTDevID_FMT, *devid ); + XP_ASSERT( len < bufLen ); + // LOG_RETURNF( "%s", buf ); return buf; } XP_UCHAR* formatMQTTDevTopic( const MQTTDevID* devid, XP_UCHAR* buf, XP_U16 bufLen ) { - XP_SNPRINTF( buf, bufLen, MQTTTopic_FMT, *devid ); +#ifdef DEBUG + int len = +#endif + XP_SNPRINTF( buf, bufLen, MQTTTopic_FMT, *devid ); + XP_ASSERT( len < bufLen ); // LOG_RETURNF( "%s", buf ); return buf; }