Ticket #194: gunnar_7_12.2.diff

File gunnar_7_12.2.diff, 3.8 KB (added by gunnar, 2 years ago)

Fix for the crash and centralized boardsize checks.

  • interface/play_gmp.c

     
    103103  } 
    104104 
    105105  gameinfo->handicap = gmp_handicap(ge); 
     106  if (!check_boardsize(gmp_size(ge), stderr)) 
     107    exit(EXIT_FAILURE); 
     108   
    106109  gnugo_clear_board(gmp_size(ge)); 
    107110 
    108111  /* Let's pretend GMP knows about komi in case something will ever change. */ 
  • interface/play_ascii.c

     
    715715            printf("\nInvalid command syntax!\n"); 
    716716            break; 
    717717          } 
    718           if (num < MIN_BOARD || num > MAX_BOARD) { 
    719             printf("\nInvalid board size: %d\n", num); 
     718          if (!check_boardsize(num, stdout)) 
    720719            break; 
    721           } 
    722720          /* Init board. */ 
    723721          board_size = num; 
    724722          clear_board(); 
  • interface/play_gtp.c

     
    442442  if (sscanf(s, "%d", &boardsize) < 1) 
    443443    return gtp_failure("boardsize not an integer"); 
    444444   
    445   if (boardsize < MIN_BOARD || boardsize > MAX_BOARD) { 
     445  if (!check_boardsize(boardsize, NULL)) { 
    446446    if (gtp_version == 1) 
    447447      return gtp_failure("unacceptable boardsize"); 
    448448    else 
  • interface/main.c

     
    510510      case OPT_BOARDSIZE: 
    511511        { 
    512512          int boardsize = atoi(gg_optarg); 
    513            
    514           if (boardsize < MIN_BOARD || boardsize > MAX_BOARD) { 
    515             fprintf(stderr, "Unsupported board size: %d. ", boardsize); 
    516             if (boardsize < MIN_BOARD) 
    517               fprintf(stderr, "Min size is %d.\n", MIN_BOARD); 
    518             else 
    519               fprintf(stderr, "Max size is %d.\n", MAX_BOARD); 
    520             fprintf(stderr, "Try `gnugo --help' for more information.\n"); 
     513 
     514          if (!check_boardsize(boardsize, stderr)) 
    521515            exit(EXIT_FAILURE); 
    522           } 
     516           
    523517          gnugo_clear_board(boardsize); 
    524518          break; 
    525519        } 
  • engine/interface.c

     
    6060 
    6161/* ---------------------------------------------------------------- */ 
    6262 
     63/* Check whether we can accept a certain boardsize. Set out to NULL to 
     64 * suppress informative messages. Return 1 for an acceptable 
     65 * boardsize, 0 otherwise. 
     66 */ 
     67int check_boardsize(int boardsize, FILE *out) 
     68{ 
     69  if (boardsize < MIN_BOARD || boardsize > MAX_BOARD) { 
     70    if (out) { 
     71      fprintf(out, "Unsupported board size: %d. ", boardsize); 
     72      if (boardsize < MIN_BOARD) 
     73        fprintf(out, "Min size is %d.\n", MIN_BOARD); 
     74      else 
     75        fprintf(out, "Max size is %d.\n", MAX_BOARD); 
     76      fprintf(out, "Try `gnugo --help' for more information.\n"); 
     77    } 
     78    return 0; 
     79  } 
     80 
     81  return 1; 
     82} 
     83 
    6384/* 
    6485 * Clear the board. 
    6586 */ 
     
    245266   
    246267  if (!sgfGetIntProperty(tree->root, "SZ", &bs)) 
    247268    bs = 19; 
    248    
    249   if (bs < MIN_BOARD || bs > MAX_BOARD) { 
    250     if (bs < MIN_BOARD) 
    251       gprintf("Boardsize too small.\n"); 
    252     else 
    253       gprintf("Boardsize too large.\n"); 
    254      
     269 
     270  if (!check_boardsize(bs, stderr)) 
    255271    return EMPTY; 
    256   } 
    257272   
    258273  handicap = 0; 
    259274  if (sgfGetIntProperty(tree->root, "HA", &handicap) && handicap > 1) 
  • engine/gnugo.h

     
    8585/* ================================================================ */ 
    8686 
    8787 
     88int check_boardsize(int boardsize, FILE *out); 
    8889void gnugo_clear_board(int boardsize); 
    8990void gnugo_play_move(int move, int color); 
    9091int gnugo_play_sgfnode(SGFNode *node, int to_move);