From 5fbda7366d698d4de6d7388d2ddde284140ba1bf Mon Sep 17 00:00:00 2001 From: Carlos Sotelo Date: Mon, 2 Mar 2026 14:46:56 +0000 Subject: [PATCH] fix fenBoard not being concurrency-safe --- fen.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fen.go b/fen.go index 9873185..723571c 100644 --- a/fen.go +++ b/fen.go @@ -53,11 +53,6 @@ func decodeFEN(fen string) (*Position, error) { }, nil } -// preallocated array to avoid strings.Split allocation -// -//nolint:gochecknoglobals // this is a preallocated array. -var rankBuffer [8]string - const ( fileMapSize = 8 pieceMapSize = 32 @@ -95,6 +90,10 @@ func clearMap[K comparable, V any](m map[K]V) { func fenBoard(boardStr string) (*Board, error) { const maxRankLen = 8 + // Local preallocated array to avoid strings.Split allocations. + // Kept local (instead of global) so fenBoard is concurrency-safe. + var rankBuffer [maxRankLen]string + // Get maps from pools m, _ := pieceMapPool.Get().(map[Square]Piece) fileMap, _ := fileMapPool.Get().(map[File]Piece)