[comp.sources.games.bugs] Conquer bug

dgibbs@bnr-fos.UUCP (David Gibbs) (07/17/89)

I have found a fairly subtle bug in the latest posting of conquer.  I can
show at least two places where it does happen, but I would not be surprised
if it occured several other places.  
  It occurs in line 419 of display.c; the line is:

  for (j=P_AYLOC-yoffset-ARMYSEE; j<=P_AYLOC-yoffset+ARMYSEE; j++)

P_AYLOC is defined as curntn->arm[armynum].yloc and is of type unsigned char.
yoffset and j are of type int
and ARMYSEE is a constant (normally 2)

The problem occurs when the terminating condition of the loop
(P_AYLOC-yoffset+ARMYSEE) is equal to -1.  WHat the C compiler
does is promote all the variables in the expression to unsigned for
the comparison, when j=-1, they are equal, but when j is increased to
0 it becomes a lot small than -1 considerred as an unsigned.  This will
cause a very long loop (possibly  endless if -1 unsigned become equal
to max unsigned).  This error could potentially occurr in any loop of
this type including lines 418, 412, and 411 of display.c at a minimum.
I don't know what the best fix for this is, but I would guess that
changing all the unsigned chars to short would be the easiest.
 
  I have include a simplified test program that demonstrates how this
can happen (and to make it obvious that those types can cause this problem.)
This program was run (and looped for a long type) and both a Sun 3/60
run SunOS 4.0 and an HP workstation of some sort running Hpux around 6.0.


----- begin code ----


main()
{
  unsigned char a = 21;
  short c = 24;
  int j;
  
  for (j = a-c-2; j<=a-c+2;j++) 
   { printf ("j is %d  ",j); }

}

------ end code -----


-David Gibbs
(dgibbs@bnr-fos.UUCP or
 ...!uunet!watmath!neat.ai.toronto.edu!utgpu!bnr-vpa!bnr-fos!dgibbs)

rae98@wash08.UUCP (rae98) (07/18/89)

In article <757@bnr-fos.UUCP> dgibbs@bnr-fos.UUCP (David Gibbs) writes:
>
>I have found a fairly subtle bug in the latest posting of conquer.
[...describes bug concerning unsigned chars...]
>-David Gibbs
>(dgibbs@bnr-fos.UUCP or
> ...!uunet!watmath!neat.ai.toronto.edu!utgpu!bnr-vpa!bnr-fos!dgibbs)

This bug was fixed with Patch #2.
-- 
===========================================================
Name:	Bob Earl		Phone:	(202) 872-6018 (wk)
UUCP:	...!uunet!wash08!rae98
BITNET:	...rae98@CAS	(At least, that is what I'm told)

pyr4@psc90.UUCP (**** The Wizard ****) (10/21/89)

	An interesting bug has shown up in conquer.  What happens is when
A player nation takes land from an NPC of a different race (without slaver),
the game takes the people from the sector and places them in their capitol.
This is not the problem. The problem is that it seems to double them, meaning
that all the people displaced get doubled.  For example: Nation Modrid
takes land from anorian displacing 30,000 people, those people are placed in 
their capitol, the very next turn anorian has an additional 30,000 people
on top of what they had the previous turn.  (This makes attacking an NPC
nation of a different race kinda pointless, unless you have slaver).
In a game we have running, it is turn 17 and anorian has 91,000 people
and they started with 17,000, not having slaver.  And they keep getting
bigger whenever a non elf nation takes land from them.

|   Ted Wisniewski    UUCP:  uunet!unh!psc90!pyr4 or: dartvax!psc90!pyr4 |
|   Plymouth State College                                               |
|   Plymouth NH, 03264              If I spoke for PSC they would pay me,|
|                                        But instead I pay them.         |