[rfk-dev] compiling rfk for 32-bit x86
Eric S. Raymond
esr at thyrsus.com
Sun Nov 18 22:29:46 PST 2012
David Wolever <david at wolever.net>:
> Alright, found the bug. Here's a reasonable patch to fix it (although I can't say with certainty that it's definitely the most reasonable):
>
> diff --git a/src/robotfindskitten.c b/src/robotfindskitten.c
> index 7074273..4afd34e 100644
> --- a/src/robotfindskitten.c
> +++ b/src/robotfindskitten.c
> @@ -354,7 +354,7 @@ void init ( unsigned int num ) {
> unsigned int i, j, temp;
>
> /* allocate memory */
> - if ( ! ( state.items = calloc ( num, sizeof ( screen_object ) ) ) ) {
> + if ( ! ( state.items = calloc ( num + 2, sizeof ( screen_object ) ) ) ) {
> fprintf ( stderr, "Cannot malloc.\n" );
> exit ( EXIT_FAILURE );
> }
Ah, the glory and wonder that is memory management in C. Sorry about that.
I was trying to simplify the code by removing several special cases in
screen-object handling. I never saw this blow up on my 64-bit machine.
One amendment: the constant 2 should be SPECIALS, which is a macro for the
number of {robot, kitten} objects in case that ever changes.
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
More information about the rfk-dev
mailing list