mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
don't run off end of array
I can't reproduce what this fixes, but if I could it'd be a crash for sure.
This commit is contained in:
parent
ee2a4aaf72
commit
7ca5fe7cc9
2 changed files with 21 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue