toward compiling with gcc8

My VSIZE is no longer legal, and apparently there's no workaround (no
way to safely figure the length of an array whose size is known at
compile time.) To avoid the risk of duplicating little constants, added
macros that define length in a way a new VSIZE can pick it up. Couldn't
make that work for struct field arrays, however, so there I'm using
constants.
This commit is contained in:
Eric House 2019-01-28 16:31:41 -08:00
parent b616f79cfd
commit d293517e7c
34 changed files with 182 additions and 155 deletions

View file

@ -232,7 +232,8 @@ static void
splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr,
int nFaceBytes, int nFaces, XP_Bool isUTF8 )
{
XP_UCHAR facesBuf[nFaces*16]; /* seems a reasonable upper bound... */
const size_t facesBufSize = nFaces*16;
XP_UCHAR facesBuf[facesBufSize]; /* seems a reasonable upper bound... */
int indx = 0;
int offsets[nFaces];
int nBytes;
@ -267,7 +268,7 @@ splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr,
}
deleteLocalRef( env, jstrs );
XP_ASSERT( indx < VSIZE(facesBuf) );
XP_ASSERT( indx < facesBufSize );
}
deleteLocalRef( env, jstrarr );
@ -572,7 +573,7 @@ makeDicts( MPFORMAL JNIEnv *env, DictMgrCtxt* dictMgr, JNIUtilCtxt* jniutil,
jsize len = (*env)->GetArrayLength( env, jdicts );
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) );
for ( int ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) {
for ( int ii = 0; ii <= MAX_NUM_PLAYERS; ++ii ) {
DictionaryCtxt* dict = NULL;
if ( ii < len ) {
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );
@ -590,7 +591,7 @@ makeDicts( MPFORMAL JNIEnv *env, DictMgrCtxt* dictMgr, JNIUtilCtxt* jniutil,
if ( 0 == ii ) {
*dictp = dict;
} else {
XP_ASSERT( ii-1 < VSIZE( dicts->dicts ) );
XP_ASSERT( ii-1 < MAX_NUM_PLAYERS );
dicts->dicts[ii-1] = dict;
}
}

View file

@ -576,9 +576,9 @@ getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr )
case COMMS_CONN_RELAY:
addr->u.ip_relay.port = getInt( env, jaddr, "ip_relay_port" );
getString( env, jaddr, "ip_relay_hostName", addr->u.ip_relay.hostName,
VSIZE(addr->u.ip_relay.hostName) );
MAX_HOSTNAME_LEN + 1 );
getString( env, jaddr, "ip_relay_invite", addr->u.ip_relay.invite,
VSIZE(addr->u.ip_relay.invite) );
MAX_INVITE_LEN + 1 );
addr->u.ip_relay.seeksPublicRoom =
getBool( env, jaddr, "ip_relay_seeksPublicRoom" );
addr->u.ip_relay.advertiseRoom =
@ -587,19 +587,19 @@ getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr )
break;
case COMMS_CONN_SMS:
getString( env, jaddr, "sms_phone", addr->u.sms.phone,
VSIZE(addr->u.sms.phone) );
MAX_PHONE_LEN + 1 );
// XP_LOGF( "%s: got SMS; phone=%s", __func__, addr->u.sms.phone );
addr->u.sms.port = getInt( env, jaddr, "sms_port" );
break;
case COMMS_CONN_BT:
getString( env, jaddr, "bt_hostName", addr->u.bt.hostName,
VSIZE(addr->u.bt.hostName) );
MAX_HOSTNAME_LEN + 1 );
getString( env, jaddr, "bt_btAddr", addr->u.bt.btAddr.chars,
VSIZE(addr->u.bt.btAddr.chars) );
MAX_BTADDR_STR_LEN );
break;
case COMMS_CONN_P2P:
getString( env, jaddr, "p2p_addr", addr->u.p2p.mac_addr,
VSIZE(addr->u.p2p.mac_addr) );
MAX_P2P_MAC_LEN + 1 );
break;
default:
XP_ASSERT(0);

View file

@ -323,7 +323,7 @@ and_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
{
UTIL_CBK_HEADER("setTimer", "(III)V" );
XP_ASSERT( why < VSIZE(util->timerStorage) );
XP_ASSERT( why < NUM_TIMERS_PLUS_ONE );
TimerStorage* storage = &util->timerStorage[why];
storage->proc = proc;
storage->closure = closure;
@ -388,7 +388,7 @@ and_dutil_getUserString( XW_DUtilCtxt* duc, XP_U16 stringCode )
XP_UCHAR* result = "";
DUTIL_CBK_HEADER("getUserString", "(I)Ljava/lang/String;" );
int index = stringCode - 1; /* see LocalizedStrIncludes.h */
XP_ASSERT( index < VSIZE( dutil->userStrings ) );
XP_ASSERT( index < N_AND_USER_STRINGS );
XP_ASSERT( 0 == (dutil->userStringsBits & (1 << index)) );
@ -417,7 +417,7 @@ and_dutil_getUserQuantityString( XW_DUtilCtxt* duc, XP_U16 stringCode, XP_U16 qu
XP_UCHAR* result = "";
DUTIL_CBK_HEADER("getUserQuantityString", "(II)Ljava/lang/String;" );
int index = stringCode - 1; /* see LocalizedStrIncludes.h */
XP_ASSERT( index < VSIZE( dutil->userStrings ) );
XP_ASSERT( index < N_AND_USER_STRINGS );
XP_UCHAR** ptrs;
dutil->userStringsBits |= 1 << index;
@ -908,7 +908,7 @@ destroyDUtil( XW_DUtilCtxt** dutilp )
(*env)->DeleteGlobalRef( env, dutil->jdutil );
}
for ( int ii = 0; ii < VSIZE(dutil->userStrings); ++ii ) {
for ( int ii = 0; ii < N_AND_USER_STRINGS; ++ii ) {
XP_UCHAR* ptr = dutil->userStrings[ii];
if ( NULL != ptr ) {
if ( 0 == (dutil->userStringsBits & (1 << ii)) ) {

View file

@ -329,7 +329,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_cleanGlobals
}
}
static const SetInfo gi_ints[] = {
#define GI_INTS_SIZE 6
static const SetInfo gi_ints[GI_INTS_SIZE] = {
ARR_MEMBER( CurGameInfo, nPlayers )
,ARR_MEMBER( CurGameInfo, gameSeconds )
,ARR_MEMBER( CurGameInfo, boardSize )
@ -338,14 +339,16 @@ static const SetInfo gi_ints[] = {
,ARR_MEMBER( CurGameInfo, forceChannel )
};
static const SetInfo gi_bools[] = {
#define GI_BOOLS_SIZE 4
static const SetInfo gi_bools[GI_BOOLS_SIZE] = {
ARR_MEMBER( CurGameInfo, hintsNotAllowed )
,ARR_MEMBER( CurGameInfo, timerEnabled )
,ARR_MEMBER( CurGameInfo, allowPickTiles )
,ARR_MEMBER( CurGameInfo, allowHintRect )
};
static const SetInfo pl_ints[] = {
#define PL_INTS_SIZE 2
static const SetInfo pl_ints[PL_INTS_SIZE] = {
ARR_MEMBER( LocalPlayer, robotIQ )
,ARR_MEMBER( LocalPlayer, secondsUsed )
};
@ -354,10 +357,10 @@ static CurGameInfo*
makeGI( MPFORMAL JNIEnv* env, jobject jgi )
{
CurGameInfo* gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*gi) );
XP_UCHAR buf[256]; /* in case needs whole path */
VDECL( XP_UCHAR, buf, 256 ); /* in case needs whole path */
getInts( env, (void*)gi, jgi, gi_ints, VSIZE(gi_ints) );
getBools( env, (void*)gi, jgi, gi_bools, VSIZE(gi_bools) );
getInts( env, (void*)gi, jgi, gi_ints, GI_INTS_SIZE );
getBools( env, (void*)gi, jgi, gi_bools, GI_BOOLS_SIZE );
/* Unlike on other platforms, gi is created without a call to
game_makeNewGame, which sets gameID. So check here if it's still unset
@ -390,7 +393,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
XP_ASSERT( !!jlp );
getInts( env, (void*)lp, jlp, pl_ints, VSIZE(pl_ints) );
getInts( env, (void*)lp, jlp, pl_ints, PL_INTS_SIZE );
lp->isLocal = getBool( env, jlp, "isLocal" );
@ -411,7 +414,8 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
return gi;
} /* makeGI */
static const SetInfo nli_ints[] = {
#define NLI_INTS_SIZE 7
static const SetInfo nli_ints[NLI_INTS_SIZE] = {
ARR_MEMBER( NetLaunchInfo, _conTypes ),
ARR_MEMBER( NetLaunchInfo, lang ),
ARR_MEMBER( NetLaunchInfo, forceChannel ),
@ -421,11 +425,13 @@ static const SetInfo nli_ints[] = {
ARR_MEMBER( NetLaunchInfo, osVers ),
};
static const SetInfo nli_bools[] = {
#define NLI_BOOLS_SIZE 1
static const SetInfo nli_bools[NLI_BOOLS_SIZE] = {
ARR_MEMBER( NetLaunchInfo, isGSM )
};
static const SetInfo nli_strs[] = {
#define NLI_STRS_SIZE 7
static const SetInfo nli_strs[NLI_STRS_SIZE] = {
ARR_MEMBER( NetLaunchInfo, dict ),
ARR_MEMBER( NetLaunchInfo, gameName ),
ARR_MEMBER( NetLaunchInfo, room ),
@ -438,17 +444,17 @@ static const SetInfo nli_strs[] = {
static void
loadNLI( JNIEnv* env, NetLaunchInfo* nli, jobject jnli )
{
getInts( env, (void*)nli, jnli, nli_ints, VSIZE(nli_ints) );
getBools( env, (void*)nli, jnli, nli_bools, VSIZE(nli_bools) );
getStrings( env, (void*)nli, jnli, nli_strs, VSIZE(nli_strs) );
getInts( env, (void*)nli, jnli, nli_ints, NLI_INTS_SIZE );
getBools( env, (void*)nli, jnli, nli_bools, NLI_BOOLS_SIZE );
getStrings( env, (void*)nli, jnli, nli_strs, NLI_STRS_SIZE );
}
static void
setNLI( JNIEnv* env, jobject jnli, const NetLaunchInfo* nli )
{
setInts( env, jnli, (void*)nli, nli_ints, VSIZE(nli_ints) );
setBools( env, jnli, (void*)nli, nli_bools, VSIZE(nli_bools) );
setStrings( env, jnli, (void*)nli, nli_strs, VSIZE(nli_strs) );
setInts( env, jnli, (void*)nli, nli_ints, NLI_INTS_SIZE );
setBools( env, jnli, (void*)nli, nli_bools, NLI_BOOLS_SIZE );
setStrings( env, jnli, (void*)nli, nli_strs, NLI_STRS_SIZE );
}
static void
@ -456,8 +462,8 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
{
// set fields
setInts( env, jgi, (void*)gi, gi_ints, VSIZE(gi_ints) );
setBools( env, jgi, (void*)gi, gi_bools, VSIZE(gi_bools) );
setInts( env, jgi, (void*)gi, gi_ints, GI_INTS_SIZE );
setBools( env, jgi, (void*)gi, gi_bools, GI_BOOLS_SIZE );
setString( env, jgi, "dictName", gi->dictName );
@ -476,7 +482,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
XP_ASSERT( !!jlp );
setInts( env, jlp, (void*)lp, pl_ints, VSIZE(pl_ints) );
setInts( env, jlp, (void*)lp, pl_ints, PL_INTS_SIZE );
setBool( env, jlp, "isLocal", lp->isLocal );
setString( env, jlp, "name", lp->name );
@ -492,7 +498,8 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
} /* setJGI */
#ifdef COMMON_LAYOUT
static const SetInfo bd_ints[] = {
#define BD_INTS_SIZE 16
static const SetInfo bd_ints[BD_INTS_SIZE] = {
ARR_MEMBER( BoardDims, left )
,ARR_MEMBER( BoardDims, top )
,ARR_MEMBER( BoardDims, width )
@ -514,13 +521,13 @@ static const SetInfo bd_ints[] = {
static void
dimsJToC( JNIEnv* env, BoardDims* out, jobject jdims )
{
getInts( env, (void*)out, jdims, bd_ints, VSIZE(bd_ints) );
getInts( env, (void*)out, jdims, bd_ints, BD_INTS_SIZE );
}
static void
dimsCtoJ( JNIEnv* env, jobject jdims, const BoardDims* in )
{
setInts( env, jdims, (void*)in, bd_ints, VSIZE(bd_ints) );
setInts( env, jdims, (void*)in, bd_ints, BD_INTS_SIZE );
}
#endif
@ -1249,7 +1256,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1zoom
XWJNI_START();
XP_Bool canInOut[2];
result = board_zoom( state->game.board, zoomBy, canInOut );
jboolean canZoom[2] = { canInOut[0], canInOut[1] };
VDECL( jboolean, canZoom, 2 ) = { canInOut[0], canInOut[1] };
setBoolArray( env, jCanZoom, VSIZE(canZoom), canZoom );
XWJNI_END();
return result;
@ -1784,7 +1791,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
XWJNI_START();
XP_ASSERT( state->game.comms );
if ( !!state->game.comms ) {
CommsAddrRec addrs[MAX_NUM_PLAYERS];
VDECL( CommsAddrRec, addrs, MAX_NUM_PLAYERS );
XP_U16 count = VSIZE(addrs);
comms_getAddrs( state->game.comms, addrs, &count );
@ -1877,7 +1884,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
switch( typ ) {
case COMMS_CONN_RELAY: {
XP_UCHAR buf[128];
VDECL( XP_UCHAR, buf, 128 );
XP_U16 len = VSIZE(buf);
if ( comms_getRelayID( comms, buf, &len ) ) {
XP_ASSERT( '\0' == buf[len-1] ); /* failed! */
@ -1890,7 +1897,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
case COMMS_CONN_BT:
case COMMS_CONN_P2P:
case COMMS_CONN_SMS: {
CommsAddrRec addrs[MAX_NUM_PLAYERS];
VDECL( CommsAddrRec, addrs, MAX_NUM_PLAYERS );
XP_U16 count = VSIZE(addrs);
comms_getAddrs( comms, addrs, &count );
@ -2010,12 +2017,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getGi
XWJNI_END();
}
static const SetInfo gsi_ints[] = {
#define GSI_INTS_SIZE 3
static const SetInfo gsi_ints[GSI_INTS_SIZE] = {
ARR_MEMBER( GameStateInfo, visTileCount ),
ARR_MEMBER( GameStateInfo, nPendingMessages ),
ARR_MEMBER( GameStateInfo, trayVisState ),
};
static const SetInfo gsi_bools[] = {
#define GSI_BOOLS_SIZE 10
static const SetInfo gsi_bools[GSI_BOOLS_SIZE] = {
ARR_MEMBER( GameStateInfo,canHint ),
ARR_MEMBER( GameStateInfo, canUndo ),
ARR_MEMBER( GameStateInfo, canRedo ),
@ -2036,8 +2046,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState
GameStateInfo info;
game_getState( &state->game, &info );
setInts( env, jgsi, (void*)&info, gsi_ints, VSIZE(gsi_ints) );
setBools( env, jgsi, (void*)&info, gsi_bools, VSIZE(gsi_bools) );
setInts( env, jgsi, (void*)&info, gsi_ints, GSI_INTS_SIZE );
setBools( env, jgsi, (void*)&info, gsi_bools, GSI_BOOLS_SIZE );
XWJNI_END();
}
@ -2330,7 +2340,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts
LengthsArray lens;
if ( 0 < dict_countWords( &iter, &lens ) ) {
XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) );
result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens,
result = makeIntArray( env, MAX_COLS_DICT+1, (jint*)&lens.lens,
sizeof(lens.lens[0]) );
}
}
@ -2348,7 +2358,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
XP_U16 depth = data->depth;
for ( int ii = 0; ii < data->idata.count; ++ii ) {
XP_UCHAR buf[16];
VDECL( XP_UCHAR, buf, 16 );
(void)dict_tilesToString( data->dict,
&data->idata.prefixes[depth*ii],
depth, buf, VSIZE(buf) );
@ -2384,7 +2394,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord
DictIterData* data = (DictIterData*)closure;
if ( NULL != data ) {
if ( dict_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) {
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
dict_wordToString( &data->iter, buf, VSIZE(buf) );
result = (*env)->NewStringUTF( env, buf );
}

View file

@ -2254,7 +2254,7 @@ figureScale( BoardCtxt* board, XP_U16 count, XP_U16 dimension, ScrollData* sd )
sd->lastVisible = count - board->zoomCount + sd->offset - 1;
if ( figureDims( sd->dims, VSIZE(sd->dims), nVis,
if ( figureDims( sd->dims, MAX_COLS, nVis,
scale, spares ) ) {
board_invalAll( board );
}
@ -2344,7 +2344,7 @@ figureBoardRect( BoardCtxt* board )
vsd->lastVisible = nVisible + vsd->offset - 1;
if ( figureDims( vsd->dims, VSIZE(vsd->dims), nVisible,
if ( figureDims( vsd->dims, MAX_COLS, nVisible,
vsd->scale, extra ) ) {
board_invalAll( board );
}

View file

@ -395,7 +395,7 @@ drawCell( BoardCtxt* board, const XP_U16 col, const XP_U16 row, XP_Bool skipBlan
/* This 'while' is only here so I can 'break' below */
while ( board->trayVisState == TRAY_HIDDEN ||
!rectContainsRect( &board->trayBounds, &cellRect ) ) {
XP_UCHAR ch[4] = {'\0'};
VDECL(XP_UCHAR, ch, 4) = {'\0'};
XP_S16 owner = -1;
XP_Bool invert = XP_FALSE;
XP_Bitmaps bitmaps;
@ -470,7 +470,7 @@ drawCell( BoardCtxt* board, const XP_U16 col, const XP_U16 row, XP_Bool skipBlan
tile, value, owner, bonus, hintAtts,
flags );
#ifdef LOG_CELL_DRAW
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
XP_LOGF( "%s(col=%d, row=%d, flags=%s)=>%s", __func__, col, row,
formatFlags(buf, VSIZE(buf), flags), success?"true":"false" );
#endif

View file

@ -734,8 +734,8 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
}
if ( STREAM_VERS_DISABLEDS <= version ) {
for ( int typ = 0; typ < VSIZE(comms->disableds); ++typ ) {
for ( int ii = 0; ii < VSIZE(comms->disableds[0]); ++ii ) {
for ( int typ = 0; typ < COMMS_CONN_NTYPES; ++typ ) {
for ( int ii = 0; ii < 2; ++ii ) {
comms->disableds[typ][ii] = 0 != stream_getBits( stream, 1 );
}
}
@ -929,8 +929,8 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream,
stream_putBytes( stream, msg->msg, msg->len );
}
for ( int typ = 0; typ < VSIZE(comms->disableds); ++typ ) {
for ( int ii = 0; ii < VSIZE(comms->disableds[0]); ++ii ) {
for ( int typ = 0; typ < COMMS_CONN_NTYPES; ++typ ) {
for ( int ii = 0; ii < 2; ++ii ) {
stream_putBits( stream, 1, comms->disableds[typ][ii] ? 1 : 0 );
}
}

View file

@ -71,7 +71,8 @@ typedef enum {
/* on Palm BtLibDeviceAddressType is a 48-bit quantity. Linux's typeis the
same size. Goal is something all platforms support */
typedef struct XP_BtAddr { XP_U8 bits[6]; } XP_BtAddr;
typedef struct XP_BtAddrStr { XP_UCHAR chars[18]; } XP_BtAddrStr;
#define MAX_BTADDR_STR_LEN 18
typedef struct XP_BtAddrStr { XP_UCHAR chars[MAX_BTADDR_STR_LEN]; } XP_BtAddrStr;
#ifdef COMMS_HEARTBEAT
# define IF_CH(a) a,

View file

@ -40,7 +40,10 @@
# endif
#endif
#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
#define VSIZE(_arr) __name_of ## _arr
#define VDECL(_type, _arr, _count) \
enum {VSIZE(_arr) = _count}; \
_type _arr[VSIZE(_arr)]
#ifndef MAX_ROWS
# define MAX_ROWS 16

View file

@ -97,7 +97,7 @@ dbg_logstream( const XWStreamCtxt* stream, const char* func, int line )
stream_copyBits( stream, end, NULL, &len );
XP_U8 buf[len];
stream_copyBits( stream, end, buf, &len );
char comment[128];
VDECL( char, comment, 128 );
XP_SNPRINTF( comment, VSIZE(comment), "%s line %d", func, line );
LOG_HEX( buf, len, comment );
} else {

View file

@ -107,7 +107,7 @@ dmgr_put( DictMgrCtxt* dmgr, const XP_UCHAR* key, DictionaryCtxt* dict )
XP_S16 loc = findFor( dmgr, key );
if ( NOT_FOUND == loc ) { /* reuse the last one */
moveToFront( dmgr, VSIZE(dmgr->pairs) - 1 );
moveToFront( dmgr, DMGR_MAX_DICTS - 1 );
DictPair* pair = dmgr->pairs; /* the head */
dict_unref( pair->dict );
pair->dict = dict_ref( dict );
@ -126,7 +126,7 @@ findFor( DictMgrCtxt* dmgr, const XP_UCHAR* key )
{
XP_S16 result = NOT_FOUND;
XP_U16 ii;
for ( ii = 0; ii < VSIZE(dmgr->pairs); ++ii ) {
for ( ii = 0; ii < DMGR_MAX_DICTS; ++ii ) {
DictPair* pair = &dmgr->pairs[ii];
if ( !!pair->key && 0 == XP_STRCMP( key, pair->key ) ) {
result = ii;
@ -151,7 +151,7 @@ static void
printInOrder( const DictMgrCtxt* dmgr )
{
XP_U16 ii;
for ( ii = 0; ii < VSIZE(dmgr->pairs); ++ii ) {
for ( ii = 0; ii < DMGR_MAX_DICTS; ++ii ) {
const XP_UCHAR* name = dmgr->pairs[ii].key;
XP_LOGF( "%s: dict[%d]: %s", __func__, ii,
(NULL == name)? "<empty>" : name );

View file

@ -454,7 +454,7 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
XP_U16 maxCountBits, maxValueBits;
XP_U16 ii, nSpecials;
XP_UCHAR* localTexts[32];
XP_U8 utf8[MAX_UNIQUE_TILES];
VDECL( XP_U8, utf8, MAX_UNIQUE_TILES );
XP_ASSERT( !dict->destructor );
dict->destructor = common_destructor;

View file

@ -223,6 +223,8 @@ typedef struct DrawCtxVTable {
const XP_Rect* rect, void** closure );
#endif
#ifndef DRAW_LINK_DIRECT
void* tableEnd;
} DrawCtxVTable; /* */
#endif

View file

@ -75,7 +75,8 @@ typedef struct MoveIterationData {
/* one bit per tile that's possible here *\/ */
typedef XP_U32 CrossBits;
typedef struct Crosscheck { CrossBits bits[2]; } Crosscheck;
#define NUM_CBITS 2
typedef struct Crosscheck { CrossBits bits[NUM_CBITS]; } Crosscheck;
struct EngineCtxt {
const ModelCtxt* model;
@ -277,7 +278,7 @@ print_savedMoves( const EngineCtxt* engine, const char* label )
{
int ii;
int pos = 0;
char buf[(NUM_SAVED_ENGINE_MOVES*10) + 3] = {0};
VDECL(char, buf, (NUM_SAVED_ENGINE_MOVES*10) + 3) = {0};
for ( ii = 0; ii < engine->nMovesToSave; ++ii ) {
if ( 0 < engine->miData.savedMoves[ii].score ) {
pos += XP_SNPRINTF( &buf[pos], VSIZE(buf)-pos, "[%d]: %d; ",
@ -725,8 +726,7 @@ figureCrosschecks( EngineCtxt* engine, XP_U16 x, XP_U16 y, XP_U16* scoreP,
XP_ASSERT( tile < MAX_UNIQUE_TILES );
tiles[0] = tile;
if ( lookup( dict, in_edge, tiles, 0, tilesAfter ) ) {
XP_ASSERT( (tile >> 5)
< (VSIZE(check->bits)) );
XP_ASSERT( (tile >> 5) < NUM_CBITS );
check->bits[tile>>5] |= (1L << (tile & 0x1F));
}

View file

@ -551,7 +551,7 @@ model_setPlayerDicts( ModelCtxt* model, const PlayerDicts* dicts )
#ifdef DEBUG
DictionaryCtxt* gameDict = model_getDictionary( model );
#endif
for ( ii = 0; ii < VSIZE(dicts->dicts); ++ii ) {
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
DictionaryCtxt* oldDict = model->vol.dicts.dicts[ii];
DictionaryCtxt* newDict = dicts->dicts[ii];
if ( oldDict != newDict ) {
@ -573,7 +573,7 @@ model_getDictionary( const ModelCtxt* model )
{
XP_U16 ii;
DictionaryCtxt* result = model->vol.dict;
for ( ii = 0; !result && ii < VSIZE(model->vol.dicts.dicts); ++ii ) {
for ( ii = 0; !result && ii < MAX_NUM_PLAYERS; ++ii ) {
result = model->vol.dicts.dicts[ii];
}
return result;
@ -594,7 +594,7 @@ static void
model_unrefDicts( ModelCtxt* model )
{
XP_U16 ii;
for ( ii = 0; ii < VSIZE(model->vol.dicts.dicts); ++ii ) {
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
dict_unref( model->vol.dicts.dicts[ii] );
model->vol.dicts.dicts[ii] = NULL;
}
@ -611,7 +611,7 @@ getPendingTileFor( const ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row,
const PendingTile* pendings;
XP_U16 ii;
XP_ASSERT( turn < VSIZE(model->players) );
XP_ASSERT( turn < MAX_NUM_PLAYERS );
player = &model->players[turn];
pendings = player->pendingTiles;
@ -2064,7 +2064,7 @@ printMovePre( ModelCtxt* model, XP_U16 XP_UNUSED(moveN), const StackEntry* entry
{
if ( entry->moveType != ASSIGN_TYPE ) {
const XP_UCHAR* format;
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
XP_UCHAR traybuf[MAX_TRAY_TILES+1];
MovePrintClosure* closure = (MovePrintClosure*)p_closure;
XWStreamCtxt* stream = closure->stream;
@ -2293,7 +2293,7 @@ scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany,
model_destroy( tmpModel );
lmi->score = score;
XP_SNPRINTF( lmi->word, VSIZE(lmi->word), "%s", data.word );
XP_SNPRINTF( lmi->word, MAX_COLS+1, "%s", data.word );
} /* scoreLastMove */
static XP_U16

View file

@ -493,7 +493,7 @@ static void
cleanupServer( ServerCtxt* server )
{
XP_U16 ii;
for ( ii = 0; ii < VSIZE(server->players); ++ii ){
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ){
ServerPlayer* player = &server->players[ii];
if ( player->engine != NULL ) {
engine_destroy( player->engine );
@ -1346,8 +1346,8 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
XP_U32 gameID;
PoolContext* pool;
#ifdef STREAM_VERS_BIGBOARD
XP_UCHAR rmtDictName[128];
XP_UCHAR rmtDictSum[64];
VDECL( XP_UCHAR, rmtDictName,128 );
VDECL( XP_UCHAR, rmtDictSum, 64 );
#endif
/* version; any dependencies here? */
@ -3172,10 +3172,11 @@ server_figureFinishBonus( const ServerCtxt* server, XP_U16 turn )
if ( 0 < nOthers ) {
Tile tile;
const DictionaryCtxt* dict = model_getDictionary( server->vol.model );
XP_U16 counts[dict_numTileFaces( dict )];
const size_t numFaces = dict_numTileFaces( dict );
XP_U16 counts[numFaces];
XP_MEMSET( counts, 0, sizeof(counts) );
model_countAllTrayTiles( server->vol.model, counts, turn );
for ( tile = 0; tile < VSIZE(counts); ++tile ) {
for ( tile = 0; tile < numFaces; ++tile ) {
XP_U16 count = counts[tile];
if ( 0 < count ) {
result += count * dict_getTileValue( dict, tile );

View file

@ -668,7 +668,7 @@ restorePartials( SMSProto* state )
&& PARTIALS_FORMAT == stream_getU8( stream ) ) {
int nFromPhones = stream_getU8( stream );
for ( int ii = 0; ii < nFromPhones; ++ii ) {
XP_UCHAR phone[32];
VDECL( XP_UCHAR, phone, 32 );
(void)stringFromStreamHere( stream, phone, VSIZE(phone) );
int nMsgIDs = stream_getU8( stream );
XP_LOGF( "%s(): got %d message records for phone %s", __func__,
@ -861,7 +861,7 @@ smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil )
SMSProto* state = smsproto_init( mpool, dutil );
const int smallSiz = 20;
const char* phones[] = {"1234", "3456", "5467", "9877"};
VDECL(char*, phones, 4) = {"1234", "3456", "5467", "9877"};
const char* buf = "asoidfaisdfoausdf aiousdfoiu asodfu oiuasdofi oiuaosiduf oaisudf oiasd f"
";oiaisdjfljiojaklj asdlkjalskdjf laksjd flkjasdlfkj aldsjkf lsakdjf lkjsad flkjsd fl;kj"
"asdifaoaosidfoiauosidufoaus doifuoaiusdoifu aoisudfoaisd foia sdoifuasodfu aosiud foiuas odfiu asd"
@ -869,7 +869,7 @@ smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil )
;
const XP_Bool forceOld = XP_TRUE;
SMSMsgArray* arrs[VSIZE(phones)];
VDECL( SMSMsgArray*, arrs, VSIZE(phones) );
for ( int ii = 0; ii < VSIZE(arrs); ++ii ) {
arrs[ii] = NULL;
}

View file

@ -409,7 +409,7 @@ getSelTiles( const BoardCtxt* board, TileBit selBits, TrayTileSet* selTiles )
for ( index = 0; selBits != 0; selBits >>= 1, ++index ) {
if ( 0 != (selBits & 0x01) ) {
Tile tile = model_getPlayerTile( model, turn, index );
XP_ASSERT( nTiles < VSIZE(selTiles->tiles) );
XP_ASSERT( nTiles < MAX_TRAY_TILES );
selTiles->tiles[nTiles++] = tile;
}
}

View file

@ -149,7 +149,7 @@ curses_draw_measureRemText( DrawCtx* XP_UNUSED(dctx),
XP_U16* width, XP_U16* height )
{
char buf[64];
char* lines[2] = {0};
VDECL( char*, lines, 2 ) = {0};
formatRemText( nTilesLeft, rect, buf, lines );
*width = 0;
@ -170,7 +170,7 @@ curses_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner,
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
char buf[32];
char* lines[2] = {0};
VDECL( char*, lines, 2 ) = {0};
formatRemText( nTilesLeft, rInner, buf, lines );
int ii;
for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) {
@ -270,7 +270,7 @@ curses_draw_measureScoreText( DrawCtx* XP_UNUSED(p_dctx),
XP_U16* width, XP_U16* height )
{
XP_UCHAR buf[100];
char* lines[3] = {0};
VDECL( char*, lines, 3 ) = {0};
formatScoreText( buf, dsi, rect, lines );
int ii;
@ -295,7 +295,7 @@ curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
curses_draw_clearRect( p_dctx, rOuter );
/* print the name and turn/remoteness indicator */
char* lines[3] = {0};
VDECL( char*, lines, 3 ) = {0};
formatScoreText( buf, dsi, rInner, lines );
int ii;
for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) {

View file

@ -57,7 +57,7 @@ curses_askLetter( CursesAppGlobals* globals, XP_UCHAR* query,
short curSelButton = 1; /* force draw by being different */
short maxWidth;
short numCtlButtons;
const char* ctlButtons[] = { "Ok", "Cancel" };
VDECL( const char*, ctlButtons, 2 ) = { "Ok", "Cancel" };
XP_Bool dismissed = XP_FALSE;
FormatInfo fi;
int len;

View file

@ -221,7 +221,7 @@ cursesUserError( CursesAppGlobals* globals, const char* format, ... )
vsprintf( buf, format, ap );
const char* buttons[] = {"OK"};
VDECL( const char*, buttons, 1 ) = {"OK"};
(void)cursesask( globals, buf, VSIZE(buttons), buttons );
va_end(ap);
@ -285,7 +285,7 @@ ask_move( gpointer data )
{
CursesAppGlobals* globals = (CursesAppGlobals*)data;
CommonGlobals* cGlobals = &globals->cGlobals;
const char* answers[] = {"Ok", "Cancel", NULL};
VDECL( const char*, answers, 3 ) = {"Ok", "Cancel", NULL};
if (0 == cursesask(globals, cGlobals->question, VSIZE(answers)-1, answers) ) {
BoardCtxt* board = cGlobals->game.board;
@ -304,7 +304,7 @@ curses_util_notifyMove( XW_UtilCtxt* uc, XWStreamCtxt* stream )
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
CommonGlobals* cGlobals = &globals->cGlobals;
XP_U16 len = stream_getSize( stream );
XP_ASSERT( len <= VSIZE(cGlobals->question) );
XP_ASSERT( len <= QUESTION_LEN );
stream_getBytes( stream, cGlobals->question, len );
(void)g_idle_add( ask_move, globals );
} /* curses_util_userQuery */
@ -315,7 +315,7 @@ ask_trade( gpointer data )
CursesAppGlobals* globals = (CursesAppGlobals*)data;
CommonGlobals* cGlobals = &globals->cGlobals;
const char* buttons[] = { "Ok", "Cancel" };
VDECL( const char*, buttons, 2 ) = { "Ok", "Cancel" };
if (0 == cursesask( globals, cGlobals->question, VSIZE(buttons), buttons ) ) {
BoardCtxt* board = cGlobals->game.board;
if ( board_commitTurn( board, XP_TRUE, XP_TRUE, NULL ) ) {
@ -353,7 +353,7 @@ cursesShowFinalScores( CursesAppGlobals* globals )
text = strFromStream( stream );
const char* buttons[] = { "Ok" };
VDECL( const char*, buttons, 1 ) = { "Ok" };
(void)cursesask( globals, text, VSIZE(buttons), buttons );
free( text );
@ -366,7 +366,7 @@ curses_util_informMove( XW_UtilCtxt* uc, XP_S16 XP_UNUSED(turn),
{
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
char* question = strFromStream( expl );
const char* buttons[] = { "Ok" };
VDECL( const char*, buttons, 1 ) = { "Ok" };
(void)cursesask( globals, question, VSIZE(buttons), buttons );
free( question );
}
@ -1412,7 +1412,7 @@ curses_util_remSelected( XW_UtilCtxt* uc )
text = strFromStream( stream );
const char* buttons[] = { "Ok" };
VDECL( const char*, buttons, 1 ) = { "Ok" };
(void)cursesask( globals, text, VSIZE(buttons), buttons );
free( text );
@ -1795,7 +1795,7 @@ cursesErrorMsgRcvd( void* closure, const XP_UCHAR* msg )
} else {
g_free( globals->lastErr );
globals->lastErr = g_strdup( msg );
const char* buttons[] = { "Ok" };
VDECL( const char*, buttons, 1 ) = { "Ok" };
(void)cursesask( globals, msg, VSIZE(buttons), buttons );
}
}
@ -2015,7 +2015,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
}
#ifdef XWFEATURE_SMS
gchar buf[32];
VDECL( gchar, buf, 32 );
const gchar* myPhone = params->connInfo.sms.myPhone;
if ( !!myPhone ) {
db_store( params->pDb, KEY_SMSPHONE, myPhone );
@ -2023,7 +2023,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
params->connInfo.sms.myPhone = myPhone = buf;
}
XP_U16 myPort = params->connInfo.sms.port;
gchar portbuf[8];
VDECL( gchar, portbuf, 8 );
if ( 0 < myPort ) {
sprintf( portbuf, "%d", myPort );
db_store( params->pDb, KEY_SMSPORT, portbuf );

View file

@ -222,7 +222,7 @@ summarize( CommonGlobals* cGlobals )
// gchar* connvia = "local";
gchar connvia[128] = {0};
XP_UCHAR relayID[32] = {0};
VDECL( XP_UCHAR, relayID, 32 ) = {0};
if ( !!game->comms ) {
nMissing = server_getMissingPlayers( game->server );
@ -341,7 +341,7 @@ getRelayIDsToRowsMap( sqlite3* pDb )
switch( sqlite3_step( ppStmt ) ) {
case SQLITE_ROW: /* have data */
{
XP_UCHAR relayID[32];
VDECL( XP_UCHAR, relayID, 32 );
int len = VSIZE(relayID);
getColumnText( ppStmt, 0, relayID, &len );
gpointer key = g_strdup( relayID );

View file

@ -1113,7 +1113,7 @@ change_dictionary( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
CommonGlobals* cGlobals = &globals->cGlobals;
LaunchParams* params = cGlobals->params;
GSList* dicts = listDicts( params );
gchar buf[265];
VDECL( gchar, buf, 265 );
gchar* name = gtkaskdict( dicts, buf, VSIZE(buf) );
if ( !!name ) {
DictionaryCtxt* dict =
@ -1662,7 +1662,7 @@ send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers,
#endif
if ( '\0' != addrs->u.sms.phone[0] && 0 < addrs->u.sms.port ) {
gchar gameName[64];
VDECL( gchar, gameName, 64 );
snprintf( gameName, VSIZE(gameName), "Game %d", cGlobals->gi->gameID );
linux_sms_invite( cGlobals->params, &nli,
@ -1844,7 +1844,7 @@ ask_password( gpointer data )
{
GtkGameGlobals* globals = (GtkGameGlobals*)data;
CommonGlobals* cGlobals = &globals->cGlobals;
XP_UCHAR buf[32];
VDECL( XP_UCHAR, buf, 32 );
XP_U16 len = VSIZE(buf);
if ( gtkpasswdask( cGlobals->askPassName, buf, &len ) ) {
BoardCtxt* board = cGlobals->game.board;
@ -2003,7 +2003,7 @@ gtk_util_informNetDict( XW_UtilCtxt* uc, XP_LangCode XP_UNUSED(lang),
{
if ( 0 != strcmp( oldName, newName ) ) {
GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure;
gchar buf[512];
VDECL( gchar, buf, 512 );
int offset = snprintf( buf, VSIZE(buf),
"dict changing from %s to %s (sum=%s).",
oldName, newName, newSum );
@ -2298,7 +2298,7 @@ gtk_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR* const msg, XP_S16 from,
XP_U32 timestamp )
{
GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure;
XP_UCHAR buf[1024];
VDECL( XP_UCHAR, buf, 1024 );
XP_UCHAR* name = "<unknown>";
if ( 0 <= from ) {
name = globals->cGlobals.gi->players[from].name;
@ -2338,7 +2338,7 @@ gtk_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player )
LastMoveInfo lmi;
if ( model_getPlayersLastScore( globals->cGlobals.game.model,
player, &lmi ) ) {
XP_UCHAR buf[128];
VDECL( XP_UCHAR, buf, 128 );
formatLMI( &lmi, buf, VSIZE(buf) );
(void)gtkask( globals->window, buf, GTK_BUTTONS_OK, NULL );
}
@ -2393,7 +2393,7 @@ gtk_util_notifyMove( XW_UtilCtxt* uc, XWStreamCtxt* stream )
/* XP_Bool freeMe = XP_FALSE; */
XP_U16 len = stream_getSize( stream );
XP_ASSERT( len <= VSIZE(cGlobals->question) );
XP_ASSERT( len <= QUESTION_LEN );
stream_getBytes( stream, cGlobals->question, len );
(void)g_idle_add( ask_move, globals );

View file

@ -67,7 +67,7 @@ conTypeToPageNum( const GtkConnsState* state, CommsConnType conType )
pageNum = ii;
break;
}
XP_ASSERT( ii < VSIZE(state->pageData) );
XP_ASSERT( ii < COMMS_CONN_NTYPES );
}
return pageNum;
}

View file

@ -745,7 +745,7 @@ gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP,
XP_Bool clearBack )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_UCHAR numbuf[3];
VDECL( XP_UCHAR, numbuf, 3 );
XP_Rect insetR = *rect;
XP_Bool isCursor = (flags & CELL_ISCURSOR) != 0;
XP_Bool valHidden = (flags & CELL_VALHIDDEN) != 0;
@ -1113,13 +1113,13 @@ formatScoreText( PangoLayout* layout, XP_UCHAR* buf, XP_U16 bufLen,
XP_U16 nTilesLeft = dsi->nTilesLeft;
XP_Bool isTurn = dsi->isTurn;
XP_S16 maxWidth = bounds->width;
XP_UCHAR numBuf[16];
VDECL( XP_UCHAR, numBuf, 16 );
int width, height;
*nLines = 1;
XP_SNPRINTF( numBuf, VSIZE(numBuf), "%d", score );
if ( (nTilesLeft < MAX_TRAY_TILES) && (nTilesLeft > 0) ) {
XP_UCHAR tmp[10];
VDECL( XP_UCHAR, tmp, 10 );
XP_SNPRINTF( tmp, VSIZE(tmp), ":%d", nTilesLeft );
(void)XP_STRCAT( numBuf, tmp );
}
@ -1134,7 +1134,7 @@ formatScoreText( PangoLayout* layout, XP_UCHAR* buf, XP_U16 bufLen,
}
/* Reformat name + ':' until it fits */
XP_UCHAR name[MAX_SCORE_LEN] = { 0 };
VDECL( XP_UCHAR, name, MAX_SCORE_LEN ) = { 0 };
if ( isTurn && maxWidth > 0 ) {
XP_U16 len = 1 + XP_STRLEN( dsi->name ); /* +1 for "\0" */
if ( scoreIsVertical ) {
@ -1181,7 +1181,7 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
XP_U16* widthP, XP_U16* heightP )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_UCHAR buf[36];
VDECL( XP_UCHAR, buf, 36 );
PangoLayout* layout;
int lineHeight = GTK_HOR_SCORE_HEIGHT, nLines;
@ -1191,9 +1191,9 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
*heightP = nLines * lineHeight;
XP_U16 playerNum = dsi->playerNum;
XP_ASSERT( playerNum < VSIZE(dctx->scoreCache) );
XP_ASSERT( playerNum < MAX_NUM_PLAYERS );
XP_SNPRINTF( dctx->scoreCache[playerNum].str,
VSIZE(dctx->scoreCache[playerNum].str), "%s", buf );
MAX_SCORE_LEN+1, "%s", buf );
dctx->scoreCache[playerNum].fontHt = lineHeight;
} /* gtk_draw_measureScoreText */
@ -1203,7 +1203,7 @@ gtk_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect,
XP_S16 curTurn, CellFlags flags )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_UCHAR buf[5];
VDECL( XP_UCHAR, buf, 5 );
XP_U16 ht;
XP_Rect localR;
GdkRGBA* cursor = ((flags & CELL_ISCURSOR) != 0)
@ -1259,7 +1259,7 @@ gtk_draw_drawTimer( DrawCtx* p_dctx, const XP_Rect* rInner,
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_Bool hadCairo = haveCairo( dctx );
if ( hadCairo || initCairo( dctx ) ) {
XP_UCHAR buf[10];
VDECL( XP_UCHAR, buf, 10 );
gtkFormatTimerText( buf, VSIZE(buf), secondsLeft );
@ -1406,8 +1406,10 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkGameGlobals* globals )
dctx->vtable = g_malloc( sizeof(*(((GtkDrawCtx*)dctx)->vtable)) );
for ( int ii = 0; ii < VSIZE(dctx->vtable); ++ii ) {
((void**)(dctx->vtable))[ii] = draw_doNothing; /* bad? */
void** ptr = (void**)dctx->vtable;
void** tableEnd = (void**)&dctx->vtable->tableEnd;
while ( ptr < tableEnd ) {
*ptr++ = draw_doNothing;
}
SET_VTABLE_ENTRY( dctx->vtable, draw_clearRect, gtk );

View file

@ -76,7 +76,7 @@ conTypeToPageNum( const GtkInviteState* state, CommsConnType conType )
pageNum = ii;
break;
}
XP_ASSERT( ii < VSIZE(state->pageData) );
XP_ASSERT( ii < COMMS_CONN_NTYPES );
}
return pageNum;
}

View file

@ -350,7 +350,7 @@ make_rematch( GtkAppGlobals* apg, const CommonGlobals* cGlobals )
comms_getAddr( comms, &addr );
addrToStream( stream, &addr );
CommsAddrRec addrs[4];
VDECL( CommsAddrRec, addrs, 4 );
XP_U16 nRecs = VSIZE(addrs);
comms_getAddrs( comms, addrs, &nRecs );
@ -478,7 +478,7 @@ setWindowTitle( GtkAppGlobals* apg )
GtkWidget* window = apg->window;
LaunchParams* params = apg->params;
gchar title[128] = {0};
VDECL( gchar, title, 128 ) = {0};
if ( !!params->dbName ) {
strcat( title, params->dbName );
}
@ -696,7 +696,7 @@ relayInviteReceived( void* closure, NetLaunchInfo* invite )
GtkAppGlobals* apg = (GtkAppGlobals*)closure;
XP_U32 gameID = invite->gameID;
sqlite3_int64 rowids[1];
VDECL( sqlite3_int64, rowids, 1 );
int nRowIDs = VSIZE(rowids);
getRowsForGameID( apg->params->pDb, gameID, rowids, &nRowIDs );
@ -782,7 +782,7 @@ smsMsgReceivedGTK( void* closure, const CommsAddrRec* from, XP_U32 gameID,
GtkAppGlobals* apg = (GtkAppGlobals*)closure;
LaunchParams* params = apg->params;
sqlite3_int64 rowids[4];
VDECL( sqlite3_int64, rowids, 4 );
int nRowIDs = VSIZE(rowids);
getRowsForGameID( params->pDb, gameID, rowids, &nRowIDs );
XP_LOGF( "%s: found %d rows for gameID %d", __func__, nRowIDs, gameID );
@ -888,7 +888,7 @@ gtkmain( LaunchParams* params )
}
#ifdef XWFEATURE_SMS
gchar buf[32];
VDECL( gchar, buf, 32 );
const gchar* myPhone = params->connInfo.sms.myPhone;
if ( !!myPhone ) {
db_store( params->pDb, KEY_SMSPHONE, myPhone );
@ -896,7 +896,7 @@ gtkmain( LaunchParams* params )
params->connInfo.sms.myPhone = myPhone = buf;
}
XP_U16 myPort = params->connInfo.sms.port;
gchar portbuf[8];
VDECL( gchar, portbuf, 8 );
if ( 0 < myPort ) {
sprintf( portbuf, "%d", myPort );
db_store( params->pDb, KEY_SMSPORT, portbuf );

View file

@ -216,8 +216,7 @@ addPhoniesCombo( GtkNewGameState* state, GtkWidget* parent )
FALSE, TRUE, 0 );
GtkWidget* phoniesCombo = gtk_combo_box_text_new();
const char* ptxts[] = { "IGNORE", "WARN", "DISALLOW" };
VDECL( const char*, ptxts, 3 ) = { "IGNORE", "WARN", "DISALLOW" };
for ( int ii = 0; ii < VSIZE(ptxts); ++ii ) {
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(phoniesCombo),
ptxts[ii] );
@ -240,7 +239,7 @@ makeNewGameDialog( GtkNewGameState* state )
GtkWidget* hbox;
#ifndef XWFEATURE_STANDALONE_ONLY
GtkWidget* roleCombo;
char* roles[] = { "Standalone", "Host", "Guest" };
VDECL( char*, roles, 3 ) = { "Standalone", "Host", "Guest" };
#endif
GtkWidget* nPlayersCombo;
GtkWidget* boardSizeCombo;

View file

@ -268,7 +268,7 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const LaunchParams* params,
XP_Bool isUTF8 = XP_FALSE;
XP_Bool hasHeader = XP_FALSE;
const XP_U8* ptr;
char path[256];
VDECL( char, path, 256 );
if ( !getDictPath( params, fileName, path, VSIZE(path) ) ) {
XP_LOGF( "%s: path=%s", __func__, path );

View file

@ -327,7 +327,7 @@ catFinalScores( const CommonGlobals* cGlobals, XP_S16 quitter )
cGlobals->params->vtMgr,
NULL, CHANNEL_NONE, catOnClose );
if ( -1 != quitter ) {
XP_UCHAR buf[128];
VDECL( XP_UCHAR, buf, 128 );
XP_SNPRINTF( buf, VSIZE(buf), "Player %s resigned\n",
cGlobals->gi->players[quitter].name );
stream_catString( stream, buf );
@ -818,7 +818,7 @@ static CmdInfoRec CmdInfoRecs[] = {
static struct option*
make_longopts()
{
int count = VSIZE( CmdInfoRecs );
int count = N_CMDS;
struct option* result = calloc( count+1, sizeof(*result) );
int ii;
for ( ii = 0; ii < count; ++ii ) {
@ -841,7 +841,7 @@ usage( char* appName, char* msg )
fprintf( stderr, "usage: %s \n", appName );
int maxWidth = 0;
for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) {
for ( ii = 0; ii < N_CMDS; ++ii ) {
const CmdInfoRec* rec = &CmdInfoRecs[ii];
int width = strlen(rec->param) + 1;
if ( rec->hasArg ) {
@ -852,7 +852,7 @@ usage( char* appName, char* msg )
}
}
for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) {
for ( ii = 0; ii < N_CMDS; ++ii ) {
const CmdInfoRec* rec = &CmdInfoRecs[ii];
char buf[120];
snprintf( buf, sizeof(buf), "--%s %s", rec->param,
@ -1624,7 +1624,7 @@ static void
testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words),
XP_U16 depth, IndexData* data, XP_U16 min, XP_U16 max )
{
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
XP_U32 ii, jj;
DictIter iter;
@ -1678,7 +1678,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
XP_U32 count = dict_countWords( &iter, &lens );
XP_U32 sum = 0;
for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) {
for ( jj = 0; jj < MAX_COLS_DICT+1; ++jj ) {
sum += lens.lens[jj];
XP_LOGF( "%d words of length %ld", lens.lens[jj], jj );
}
@ -1692,7 +1692,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
gotOne;
gotOne = dict_getNextWord( &iter ) ) {
XP_ASSERT( dict_getPosition( &iter ) == jj );
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
dict_wordToString( &iter, buf, VSIZE(buf) );
# ifdef PRINT_ALL
fprintf( stderr, "%.6ld: %s\n", jj, buf );
@ -1708,7 +1708,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
gotOne;
++jj, gotOne = dict_getPrevWord( &iter ) ) {
XP_ASSERT( dict_getPosition(&iter) == count-jj-1 );
XP_UCHAR buf[64];
VDECL( XP_UCHAR, buf, 64 );
dict_wordToString( &iter, buf, VSIZE(buf) );
# ifdef PRINT_ALL
fprintf( stderr, "%.6ld: %s\n", jj, buf );
@ -1750,13 +1750,13 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
XP_ASSERT( 0 );
}
XP_ASSERT( word.index == indices[ii] );
XP_UCHAR buf1[64];
VDECL( XP_UCHAR, buf1, 64 );
dict_wordToString( dict, &word, buf1, VSIZE(buf1) );
XP_UCHAR buf2[64] = {0};
VDECL( XP_UCHAR, buf2, 64 ) = {0};
if ( ii > 0 && dict_getNthWord( dict, &word, indices[ii]-1 ) ) {
dict_wordToString( dict, &word, buf2, VSIZE(buf2) );
}
char prfx[8];
VDECL( char, prfx, 8 );
dict_tilesToString( dict, &prefixes[depth*ii], depth, prfx,
VSIZE(prfx) );
fprintf( stderr, "%d: index: %ld; prefix: %s; word: %s (prev: %s)\n",
@ -1774,8 +1774,8 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii );
XP_S16 lenMatched = dict_findStartsWith( &iter, prefix );
if ( 0 <= lenMatched ) {
XP_UCHAR buf[32];
XP_UCHAR bufPrev[32] = {0};
VDECL( XP_UCHAR, buf, 32 );
VDECL( XP_UCHAR, bufPrev, 32 ) = {0};
dict_wordToString( &iter, buf, VSIZE(buf) );
/* This doesn't work with synonyms like "L-L" for "L·L" */
@ -1832,7 +1832,7 @@ dumpDict( DictionaryCtxt* dict )
for ( XP_Bool result = dict_firstWord( &iter );
result;
result = dict_getNextWord( &iter ) ) {
XP_UCHAR buf[32];
VDECL( XP_UCHAR, buf, 32 );
dict_wordToString( &iter, buf, VSIZE(buf) );
fprintf( stdout, "%s\n", buf );
}
@ -1841,7 +1841,7 @@ dumpDict( DictionaryCtxt* dict )
static void
trimDictPath( const char* input, char* buf, int bufsiz, char** path, char** dict )
{
char unlinked[256];
VDECL( char, unlinked, 256 );
XP_ASSERT( strlen(input) < VSIZE(unlinked) );
ssize_t siz = readlink( input, unlinked, VSIZE(unlinked) );
if ( 0 <= siz ) {
@ -1883,7 +1883,7 @@ getDictPath( const LaunchParams *params, const char* name,
result[0] = '\0';
for ( iter = params->dictDirs; !!iter; iter = iter->next ) {
const char* path = iter->data;
char buf[256];
VDECL( char, buf, 256 );
int len = snprintf( buf, VSIZE(buf), "%s/%s.xwd", path, name );
if ( len < VSIZE(buf) && file_exists( buf ) ) {
snprintf( result, resultLen, "%s", buf );
@ -2064,7 +2064,7 @@ main( int argc, char** argv )
GSList* testPrefixes = NULL;
char* testMinMax = NULL;
#endif
char dictbuf[256];
VDECL( char, dictbuf, 256 );
char* dict;
char* path;

View file

@ -68,7 +68,7 @@ linux_debugf( const char* format, ... )
void
linux_backtrace( void )
{
void* buffer[128];
VDECL( void*, buffer, 128 );
int nFound = backtrace( buffer, VSIZE(buffer) );
XP_ASSERT( nFound < VSIZE(buffer) );
char** traces = backtrace_symbols( buffer, nFound );
@ -105,10 +105,13 @@ linux_util_makeEmptyDict( XW_UtilCtxt* XP_UNUSED_DBG(uctx) )
#define TL BONUS_TRIPLE_LETTER
#define TW BONUS_TRIPLE_WORD
#define SC_BOARD_SIZE 36
#define SEVENTEEN_BOARD_SIZE 45
static XWBonusType*
bonusesFor( XP_U16 boardSize, XP_U16* len )
{
static XWBonusType scrabbleBoard[] = {
static XWBonusType scrabbleBoard[SC_BOARD_SIZE] = {
TW,//EM,EM,DL,EM,EM,EM,TW,
EM,DW,//EM,EM,EM,TL,EM,EM,
@ -122,7 +125,7 @@ bonusesFor( XP_U16 boardSize, XP_U16* len )
TW,EM,EM,DL,EM,EM,EM,DW,
}; /* scrabbleBoard */
static XWBonusType seventeen[] = {
static XWBonusType seventeen[SEVENTEEN_BOARD_SIZE] = {
TW,//EM,EM,DL,EM,EM,EM,TW,
EM,DW,//EM,EM,EM,TL,EM,EM,
@ -140,10 +143,10 @@ bonusesFor( XP_U16 boardSize, XP_U16* len )
XWBonusType* result = NULL;
if ( boardSize == 15 ) {
result = scrabbleBoard;
*len = VSIZE(scrabbleBoard);
*len = SC_BOARD_SIZE;
} else if ( boardSize == 17 ) {
result = seventeen;
*len = VSIZE(seventeen);
*len = SEVENTEEN_BOARD_SIZE;
}
return result;
@ -481,7 +484,7 @@ formatConfirmTrade( CommonGlobals* cGlobals, const XP_UCHAR** tiles,
}
tileBuf[offset-2] = '\0';
snprintf( cGlobals->question, VSIZE(cGlobals->question),
snprintf( cGlobals->question, QUESTION_LEN,
"Are you sure you want to trade the selected tiles (%s)?",
tileBuf );
}

View file

@ -188,6 +188,7 @@ typedef struct _TimerInfo {
typedef void (*OnSaveFunc)( void* closure, sqlite3_int64 rowid,
XP_Bool firstTime );
#define QUESTION_LEN 256*4
struct CommonGlobals {
LaunchParams* params;
CommonPrefs cp;
@ -223,7 +224,7 @@ struct CommonGlobals {
/* Saved state from util method to response method */
XP_U16 selPlayer;
char question[256*4];
char question[QUESTION_LEN];
const XP_UCHAR* askPassName;
XP_U16 nTiles;
XP_U16 nToPick;

View file

@ -32,6 +32,8 @@
#define MAX_MOVE_CHECK_MS ((XP_U16)(1000 * 60 * 60 * 24))
#define RELAY_API_PROTO "http"
#define HOST_LEN 64
typedef struct _RelayConStorage {
pthread_t mainThread;
guint moveCheckerID;
@ -50,7 +52,7 @@ typedef struct _RelayConStorage {
uint32_t nextID;
XWPDevProto proto;
LaunchParams* params;
XP_UCHAR host[64];
XP_UCHAR host[HOST_LEN];
int nextTaskID;
} RelayConStorage;
@ -259,7 +261,7 @@ relaycon_init( LaunchParams* params, const RelayConnProcs* procs,
pthread_mutex_init( &storage->gotDataMutex, NULL );
g_timeout_add( 50, gotDataTimer, storage );
XP_ASSERT( XP_STRLEN(host) < VSIZE(storage->host) );
XP_ASSERT( XP_STRLEN(host) < HOST_LEN );
XP_MEMCPY( storage->host, host, XP_STRLEN(host) + 1 );
} else {
storage->socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

View file

@ -281,6 +281,8 @@ typedef unsigned short CookieID;
#define COOKIE_ID_NONE 0
#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
#ifndef VSIZE
# define VSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
#endif
#endif