[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: Tanbo (game.cp?) Bug




>It appears that game.cpp is not properly moving
>
>	-option
>
>arguments to the parameters list.  Anyone have time to look into this?
>
>Richard

Actually, it's an off by 1 bug.  The -option is getting parsed and
moved, but an extra argument is getting processed in Game::Challenge()
due to the off-by-1.  If no options are present it processes one more
argument than is present.  It's surprising this hasn't caused other
problems.  Perhaps argv[argc] is "" or something that isn't causing
damage.

Using postdecrement in a loop test is confusing, and no doubt
contributed to this bug.  The patch enclosed at end of this message
fixes this, and also eliminates the other postdecrements of argc in
loops in game.cpp.  The bug is at line 1016.

Best,
- Scott

>Forwarded message:
>> Subject:  Message from rolle via PBM Server
>> 
>> I just got this, what's wrong?
>> 
>> 
>> >Tanbo is a 2 or 4 player game.  3 cannot play
>> >
>> >Original message follows:
>> 
>> stuff deleted
>> >>Date: Fri, 09 May 1997 23:37:06 +0100
>> >>To: "Richard's PBeM Server" <pbmserv@gamerz.net>
>> >>From: roland.johansson@mbox2.swipnet.se (Roland Johansson)
>> >>Subject: tanbo challenge -small jeroen rolle
>> 
>> I tried to send that subject, but it didn't work
>> is it disabled?
>> 
>> Best wishes
>> Roland J.
>> -------
>> It is in the blood of genius
>> to love play for its own sake
>>                -Gelett Burgess
>> 
>> My homepage:                       ***************************************
>> http://home1.swipnet.se/~w-15221   *       don't miss this site !!!      *
>> my address:                        *www.sega.com/cgi-bin/comics/viewer.pl*
>> roland.johansson@mbox2.swipnet.se  ***************************************
>> 
>> 
>
>
>-- 
> /  \__  | Richard Rognlie / Sr. Internet Developer / Erol's Internet
> \__/  \ | E-Mail: rrognlie@gamerz.net       
> /  \__/ | Phone:  (Office) 703.321.8000x2222  (Home) 703.361.4764   
> \__/    | WWW:    http://www.gamerz.net/~rrognlie/ 


*** buggy/game.cpp	Sat May 10 00:58:43 1997
--- game.cpp	Sat May 10 01:02:45 1997
***************
*** 843,854 ****
      if (ptr) ptr[-1] = '#';		// if we stripped '#', restore it
      if (argc > 0 && is_board) {
          // All args are board names
!         while (argc-- > 0) {
  	    if ( is_board && (!ptr || Regenerate(atoi(ptr))) && (this->*fct)(who,fp) )
                  success.Add(*argv);
              else
                  failure.Add(*argv);
!             argv++;
              if (argc) {
  		if ((ptr = strrchr (*argv, '#')) != NULL) *ptr++ = '\0';
                  is_board = Read(*argv);
--- 843,854 ----
      if (ptr) ptr[-1] = '#';		// if we stripped '#', restore it
      if (argc > 0 && is_board) {
          // All args are board names
!         while (argc > 0) {
  	    if ( is_board && (!ptr || Regenerate(atoi(ptr))) && (this->*fct)(who,fp) )
                  success.Add(*argv);
              else
                  failure.Add(*argv);
!             argc--, argv++;
              if (argc) {
  		if ((ptr = strrchr (*argv, '#')) != NULL) *ptr++ = '\0';
                  is_board = Read(*argv);
***************
*** 860,866 ****
          // Args are selectors
          int active = 0, inactive = 0, next = 0, tournament = 0, standard = 0;
          StringList play;
!         while (argc-- > 0) {
              if (!Strcmp(*argv, "active"))
                  active = 1;
              else if (!Strcmp(*argv, "inactive"))
--- 860,866 ----
          // Args are selectors
          int active = 0, inactive = 0, next = 0, tournament = 0, standard = 0;
          StringList play;
!         while (argc > 0) {
              if (!Strcmp(*argv, "active"))
                  active = 1;
              else if (!Strcmp(*argv, "inactive"))
***************
*** 878,884 ****
              else
                  play.Add(*argv);    /* Ok to show invalid players -- 
                               * they may have left pbmserv */
!             argv++;
          }
          if (active + inactive + next > 1)
              return Error("Cannot process games that are more than one of active, inactive or next");
--- 878,884 ----
              else
                  play.Add(*argv);    /* Ok to show invalid players -- 
                               * they may have left pbmserv */
!             argc--, argv++;
          }
          if (active + inactive + next > 1)
              return Error("Cannot process games that are more than one of active, inactive or next");
***************
*** 1013,1019 ****
      // Validate users
      StringList invalid, dontwant;
      rejecters.ReadFile(GameType());
!     while (argc-- >= 0) {
          if (CheckUserid(player=*argv,"") == BAD_USER)
              invalid.Add(*argv);
          else if (rejecters.Has(*argv)>=0)
--- 1013,1019 ----
      // Validate users
      StringList invalid, dontwant;
      rejecters.ReadFile(GameType());
!     while (argc > 0) {
          if (CheckUserid(player=*argv,"") == BAD_USER)
              invalid.Add(*argv);
          else if (rejecters.Has(*argv)>=0)
***************
*** 1022,1028 ****
              players.Add(*argv);
              resigned.Add(0);
          }
!         argv++;
      }
      if (invalid.Count()||dontwant.Count()) {
          Mail mail;
--- 1022,1028 ----
              players.Add(*argv);
              resigned.Add(0);
          }
!         argc--, argv++;
      }
      if (invalid.Count()||dontwant.Count()) {
          Mail mail;
***************
*** 1877,1887 ****
          argc--,argv++;
      }
  
!     while (argc-- > 0) {
          if (!status.IsActive())
              return Error("The game has ended");
  
!         const char *move = *(argv++);
          const char *formatted_move;
          if (!Strcmp(move,"pass") || !Strcmp(move,SkipMove()))
              if (CanPass())
--- 1877,1887 ----
          argc--,argv++;
      }
  
!     while (argc > 0) {
          if (!status.IsActive())
              return Error("The game has ended");
  
!         const char *move = *(argv++);  argc--;
          const char *formatted_move;
          if (!Strcmp(move,"pass") || !Strcmp(move,SkipMove()))
              if (CanPass())