Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] Re: myrand does the wrong thing
Home

[Freeciv-Dev] Re: myrand does the wrong thing

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Cameron Morland <cameron@xxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: myrand does the wrong thing
From: Raimar Falke <rf13@xxxxxxxxxxxxxxxxx>
Date: Mon, 2 Dec 2002 19:32:54 +0100

On Mon, Dec 02, 2002 at 11:35:34AM -0500, Cameron Morland wrote:

> I was testing what happens on very small maps, and I found that the
> system broke consistently with a ysize less than 18. A bit of gdb,
> and the problem is that myrand is being called with a value of zero,
> which returns a random number between zero and MAX_UINT32. If we're
> looking for a very small random number, getting a very large random
> number will produce problems.
> 
> This patch makes myrand(size) return zero immediately if its
> argument is less than or equal to 1. Additionally, it fixes the only
> place where myrand(0) is explicitely called (in client
> initialization), so now it calls myrand(MAX_UINT32). If you want a
> random number between zero and MAX_UINT32, why not ask for one?

Please use RT. Send the bug report/patch to rt@xxxxxxxxxxxxxx or you
the web interface at rt.freeciv.org.

> @@ -88,6 +89,8 @@ RANDOM_TYPE myrand(RANDOM_TYPE size) 
>      divisor = MAX_UINT32/size;
>      max = size * divisor - 1;
>    }
> +  else
> +    return 0;

Missing {}

In general the patch is ok.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "#!/usr/bin/perl -w
  if ( `date +%w` != 1 ) {
    die "This script only works on Mondays." ;
  }"
    -- from chkars.pl by Cornelius Krasel in de.comp.os.linux.misc


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: myrand does the wrong thing, Raimar Falke <=