# HG changeset patch # User Mike Becker # Date 1784402318 -7200 # Node ID 7e3f2d462bb6d31392b65a560f4b12ff74d3c7a4 # Parent 942a0cef9ff5d9ac8045708196ae85220ad8635a make eval_move() and check_move() not change their input string diff -r 942a0cef9ff5 -r 7e3f2d462bb6 src/chess/rules.c --- a/src/chess/rules.c Sat Jul 18 21:18:07 2026 +0200 +++ b/src/chess/rules.c Sat Jul 18 21:18:38 2026 +0200 @@ -716,15 +716,17 @@ } } -static int eval_move1(char *mstr, Move *move, uint8_t color) { +static int eval_move1(const char *pstr, Move *move, uint8_t color) { memset(move, 0, sizeof(Move)); move->fromfile = POS_UNSPECIFIED; move->fromrow = POS_UNSPECIFIED; - size_t len = strlen(mstr); + size_t len = strlen(pstr); if (len < 1 || len > 6) { return INVALID_MOVE_SYNTAX; } + char mstr[8]; + strcpy(mstr, pstr); /* evaluate check/checkmate flags */ if (mstr[len-1] == '+' || mstr[len-1] == '#') { @@ -844,7 +846,8 @@ return VALID_MOVE_SYNTAX; } -int eval_move(GameState *gamestate, char *mstr, Move *move, uint8_t color) { +int eval_move(GameState *gamestate, const char *mstr, + Move *move, uint8_t color) { int result = eval_move1(mstr, move, color); if (result == VALID_MOVE_SYNTAX) { if (move->fromfile == POS_UNSPECIFIED @@ -857,7 +860,7 @@ return result; } -int check_move(char *mstr, uint8_t color) { +int check_move(const char *mstr, uint8_t color) { Move move; return eval_move1(mstr, &move, color); } diff -r 942a0cef9ff5 -r 7e3f2d462bb6 src/chess/rules.h --- a/src/chess/rules.h Sat Jul 18 21:18:07 2026 +0200 +++ b/src/chess/rules.h Sat Jul 18 21:18:38 2026 +0200 @@ -334,7 +334,8 @@ * @param color the color of the player to evaluate the move for * @return status code (see macros in this file for the list of codes) */ -int eval_move(GameState *gamestate, char *mstr, Move *move, uint8_t color); +int eval_move(GameState *gamestate, const char *mstr, + Move *move, uint8_t color); /** * Syntactically checks a move without verifying that a piece exists that is @@ -344,7 +345,7 @@ * @param color the color of the player to evaluate the move for * @return status code (see macros in this file for the list of codes) */ -int check_move(char *mstr, uint8_t color); +int check_move(const char *mstr, uint8_t color); /** * Validates move by applying chess rules.