From 5e6d63249d1251ca0838a257ff9671383edc15b1 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Wed, 15 Sep 2010 17:01:45 +0800 Subject: [PATCH] Attempt at fixing memory mess. --- src/link/C/agents/c_wash.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; } -- 2.20.1