diff --git a/xwords4/android/jni/andutils.c b/xwords4/android/jni/andutils.c index 6a1134a94..6d92ab83a 100644 --- a/xwords4/android/jni/andutils.c +++ b/xwords4/android/jni/andutils.c @@ -854,17 +854,24 @@ msgAndTopicProc( void* closure, const XP_UCHAR* topic, MTPData* mtp = (MTPData*)closure; JNIEnv* env = mtp->env; - const XP_UCHAR* ptr = mtp->topics[mtp->count] = &mtp->storage[mtp->offset]; - size_t siz = XP_SNPRINTF( (char*)ptr, VSIZE(mtp->storage) - mtp->offset, - "%s", topic ); - XP_ASSERT( siz < VSIZE(mtp->storage) - mtp->offset ); - XP_USE( siz ); - mtp->offset += 1 + XP_STRLEN(ptr); + if ( VSIZE(mtp->topics) <= mtp->count ) { + XP_LOGFF( "exausted space for topics; dropping" ); + } else { + const XP_UCHAR* ptr = &mtp->storage[mtp->offset]; + size_t siz = XP_SNPRINTF( (char*)ptr, VSIZE(mtp->storage) - mtp->offset, + "%s", topic ); + if ( siz >= VSIZE(mtp->storage) - mtp->offset ) { + XP_LOGFF( "exausted space for data; dropping" ); + } else { + mtp->topics[mtp->count] = ptr; + mtp->offset += 1 + XP_STRLEN(ptr); - mtp->jPackets[mtp->count] = makeByteArray( env, msgLen, (const jbyte*)msgBuf ); + mtp->jPackets[mtp->count] = makeByteArray( env, msgLen, (const jbyte*)msgBuf ); - ++mtp->count; - XP_ASSERT( mtp->count < VSIZE(mtp->topics) ); + ++mtp->count; + XP_LOGFF( "mtp->count now: %d", mtp->count ); + } + } } jobject diff --git a/xwords4/android/jni/andutils.h b/xwords4/android/jni/andutils.h index ec0eb3c45..762ed19f4 100644 --- a/xwords4/android/jni/andutils.h +++ b/xwords4/android/jni/andutils.h @@ -121,14 +121,16 @@ void deleteLocalRefs( JNIEnv* env, ... ); JNIEnv* waitEnvFromGlobals(); +#define N_DATA_PACKETS 4 typedef struct _MTPData { JNIEnv* env; int count; - const XP_UCHAR* topics[4]; - jbyteArray jPackets[4]; - XP_UCHAR storage[256]; + const XP_UCHAR* topics[N_DATA_PACKETS]; + jbyteArray jPackets[N_DATA_PACKETS]; + XP_UCHAR storage[N_DATA_PACKETS*128]; int offset; } MTPData; +#undef N_DATA_PACKETS void msgAndTopicProc( void* closure, const XP_UCHAR* topic, const XP_U8* msgBuf, XP_U16 msgLen );