Skip to main content
added 17 characters in body
Source Link
vnp
  • 56.8k
  • 4
  • 51
  • 140
  • Handle malformed FEN

    The code happily accepts /9/. It doesn't check that the rank spells out exactly 8 files. It doesn't check that the input spells out exactly 8 ranks. In both cases, hello buffer overflow.

    It also doesn't check that the piece letter makes sense (may be good for the fairy chess. but still ...).

  • fen.substr(iter + 1, 3); looks strange, as it has no effect. Along the same line, I don't see en passant handling.fen.substr(iter + 1, 3); looks strange, as it has no effect. Along the same line, I don't see en passant handling.

  • The code assumes that there is exacly one space between board and turn, and between turn and castling rights. I am not sure that FEN standard mandates it. If it does not, allow multiple spaces; if it does, prepare to handle a malformed one.

  • More functions please, aka no naked loops

    Every time you feel compelled to annotate a loop with a comment like

      // parse the board first
    

    consider to factor the loop out into a function with the proper name. Something along the lines of

      void Chess::parse_fen (const std::string& fen)
      {
          std::string::iterator it = fen.begin();
          it = parse_board(it);
          it = parse_turn(it);
          it = parse_castle_rights(it);
          ....
      }
    
  • Handle malformed FEN

    The code happily accepts /9/. It doesn't check that the rank spells out exactly 8 files. It doesn't check that the input spells out exactly 8 ranks. In both cases, hello buffer overflow.

    It also doesn't check that the piece letter makes sense (may be good for the fairy chess. but still ...).

  • fen.substr(iter + 1, 3); looks strange, as it has no effect. Along the same line, I don't see en passant handling.

  • The code assumes that there is exacly one space between board and turn, and between turn and castling rights. I am not sure that FEN standard mandates it. If it does not, allow multiple spaces; if it does, prepare to handle a malformed one.

  • More functions please, aka no naked loops

    Every time you feel compelled to annotate a loop with a comment like

      // parse the board first
    

    consider to factor the loop out into a function with the proper name. Something along the lines of

      void Chess::parse_fen (const std::string& fen)
      {
          std::string::iterator it = fen.begin();
          it = parse_board(it);
          it = parse_turn(it);
          it = parse_castle_rights(it);
          ....
      }
    
  • Handle malformed FEN

    The code happily accepts /9/. It doesn't check that the rank spells out exactly 8 files. It doesn't check that the input spells out exactly 8 ranks. In both cases, hello buffer overflow.

    It also doesn't check that the piece letter makes sense (may be good for the fairy chess. but still ...).

  • fen.substr(iter + 1, 3); looks strange, as it has no effect. Along the same line, I don't see en passant handling.

  • The code assumes that there is exacly one space between board and turn, and between turn and castling rights. I am not sure that FEN standard mandates it. If it does not, allow multiple spaces; if it does, prepare to handle a malformed one.

  • More functions please, aka no naked loops

    Every time you feel compelled to annotate a loop with a comment like

      // parse the board first
    

    consider to factor the loop out into a function with the proper name. Something along the lines of

      void Chess::parse_fen (const std::string& fen)
      {
          std::string::iterator it = fen.begin();
          it = parse_board(it);
          it = parse_turn(it);
          it = parse_castle_rights(it);
          ....
      }
    
Source Link
vnp
  • 56.8k
  • 4
  • 51
  • 140

  • Handle malformed FEN

    The code happily accepts /9/. It doesn't check that the rank spells out exactly 8 files. It doesn't check that the input spells out exactly 8 ranks. In both cases, hello buffer overflow.

    It also doesn't check that the piece letter makes sense (may be good for the fairy chess. but still ...).

  • fen.substr(iter + 1, 3); looks strange, as it has no effect. Along the same line, I don't see en passant handling.

  • The code assumes that there is exacly one space between board and turn, and between turn and castling rights. I am not sure that FEN standard mandates it. If it does not, allow multiple spaces; if it does, prepare to handle a malformed one.

  • More functions please, aka no naked loops

    Every time you feel compelled to annotate a loop with a comment like

      // parse the board first
    

    consider to factor the loop out into a function with the proper name. Something along the lines of

      void Chess::parse_fen (const std::string& fen)
      {
          std::string::iterator it = fen.begin();
          it = parse_board(it);
          it = parse_turn(it);
          it = parse_castle_rights(it);
          ....
      }