From 1f5ff11a9ae34d972d41214e339baeae1387bc2e Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 25 Mar 2020 22:27:01 -0700 Subject: [PATCH] recover from corrupt chat player index This should never happen, but it did and I want to stop local crashes to investigate. --- .../src/main/java/org/eehouse/android/xw4/ChatDelegate.java | 5 +++-- xwords4/common/server.c | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java index 4d62cef2a..4597b4b32 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java @@ -162,8 +162,9 @@ public class ChatDelegate extends DelegateBase { TextView view = (TextView)row.findViewById( R.id.chat_row_text ); view.setText( msg ); view = (TextView)row.findViewById( R.id.chat_row_name ); - view.setText( getString( R.string.chat_sender_fmt, - m_names[playerIndx] ) ); + + String name = playerIndx < m_names.length ? m_names[playerIndx] : ""; + view.setText( getString( R.string.chat_sender_fmt, name ) ); if ( tsSeconds > 0 ) { long now = 1000L * Utils.getCurSeconds(); diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 771d92987..6a7a58180 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -722,6 +722,7 @@ sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR* msg, XWStreamCtxt* stream = messageStreamWithHeader( server, devIndex, XWPROTO_CHAT ); stringToStream( stream, msg ); + XP_ASSERT( from < server->vol.gi->nPlayers ); stream_putU8( stream, from ); stream_putU32( stream, timestamp ); stream_destroy( stream ); @@ -765,6 +766,7 @@ receiveChat( ServerCtxt* server, XWStreamCtxt* incoming ) sendChatToClientsExcept( server, sourceClientIndex, msg, from, timestamp ); } + XP_ASSERT( from < server->vol.gi->nPlayers ); util_showChat( server->vol.util, msg, from, timestamp ); XP_FREE( server->mpool, msg ); return XP_TRUE;