tags 234448 + patch
thanks

Hi,

I hit this bug too, today, and spent a few hours tracking it down.

It's simple, really. The file trek.h contains:

struct quad             /* definition for each quadrant */
{
        unsigned char   bases;  /* number of bases in this quadrant */
        char    klings;         /* number of Klingons in this quadrant */
        char    holes;          /* number of black holes in this quadrant */
        int     scanned;        /* star chart entry (see below) */
        short   stars;          /* number of stars in this quadrant */
        char    qsystemname;    /* starsystem name (see below) */
};

And then in setup.c, the following line is found:

q->stars = ranf(9) + 1;
q->holes = ranf(3) - q->stars / 5;

This assumes char is signed, which it isn't on powerpc (and s390). As a
result, q->holes may end up being negative (if ranf(3) returns 0, for
example) which gets turned into either 255 or 254. Having that much
black holes in a quadrant will result in trek looping in initquad() when
it tries to find an empty spot to put the black hole.

The following patch should fix that:

--- setup.c     2003-12-17 03:47:37.000000000 +0100
+++ setup.c-fixed       2008-11-13 14:33:32.000000000 +0100
@@ -234,11 +234,14 @@
        for (i = 0; i < NQUADS; i++)
                for (j = 0; j < NQUADS; j++)
                {
+                       signed char tmp;
                        q = &Quad[i][j];
                        q->klings = q->bases = 0;
                        q->scanned = -1;
                        q->stars = ranf(9) + 1;
-                       q->holes = ranf(3) - q->stars / 5;
+                       tmp = ranf(3) - q->stars / 5;
+                       tmp = tmp < 0 ? 0 : tmp;
+                       q->holes = tmp;
                        q->qsystemname = 0;
                }
 
Not tested, but trivial enough. Alternatively, the definition could be
made explicit so that the "char" definition of the "holes" member of
struct quad is a signed char everywhere.

-- 
<Lo-lan-do> Home is where you have to wash the dishes.
  -- #debian-devel, Freenode, 2004-09-22



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to