From: Daniel Axtens Date: Wed, 15 Sep 2010 09:01:45 +0000 (+0800) Subject: Attempt at fixing memory mess. X-Git-Tag: v02.1 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9ea7cd888c30fbaa6f6531875ee9327d784f6995;p=progcomp10.git Attempt at fixing memory mess. --- diff --git a/src/link/C/agents/c_wash.c b/src/link/C/agents/c_wash.c index e0d0357..557464e 100644 --- a/src/link/C/agents/c_wash.c +++ b/src/link/C/agents/c_wash.c @@ -32,10 +32,12 @@ gospel on the number of agents you're going to see. */ #define NUMBEROFAGENTSGUESS 100 +typedef char agentName[MAXAGENTNAMELEN]; + /* data for each instance of my agent */ typedef struct { /* The name of the n-th foe who has beaten us */ - char (*defeatingFoes)[MAXAGENTNAMELEN]; + agentName * defeatingFoes; /* The length of the array, and how far we are along it */ size_t foesLen; @@ -64,7 +66,7 @@ int haveLostTo( wash_data * me, char * foeName ) { void * Initialise( char * myName ) { wash_data * me = malloc( sizeof( wash_data ) ); - me->defeatingFoes = calloc( NUMBEROFAGENTSGUESS, sizeof( MAXAGENTNAMELEN*sizeof(char) ) ); + me->defeatingFoes = calloc( NUMBEROFAGENTSGUESS, sizeof( agentName ) ); me->foesLen = NUMBEROFAGENTSGUESS; me->foesCount = 0; @@ -159,7 +161,7 @@ void Results( void * this, char * foeName, int isInstigatedByYou, if (me->foesCount==me->foesLen) { /* double the array size. This should error check, but doesn't */ me->defeatingFoes = realloc( me->defeatingFoes, - me->foesLen*2*sizeof( MAXAGENTNAMELEN*sizeof(char) ) ); + me->foesLen*2*sizeof( agentName ) ); me->foesLen *= 2; }