shithub: moonfish

Download patch

ref: 9ea4043307d508c1b82ae7e358177f4587f988ef
parent: 91e6d5fba63d1e68d751c0fc7823838afa7b7756
author: zamfofex <zamfofex@twdb.moe>
date: Mon Jan 6 20:17:23 EST 2025

remove undefined behavior

--- a/search.c
+++ b/search.c
@@ -211,7 +211,7 @@
 		}
 	}
 	
-	qsort(node->children, child_count, sizeof *node, &moonfish_compare);
+	if (child_count > 0) qsort(node->children, child_count, sizeof *node, &moonfish_compare);
 	if (child_count == 0 && node->children != NULL) free(node->children);
 	node->count = child_count;
 }
@@ -441,7 +441,7 @@
 	
 #endif
 	
-	qsort(root->node.children, root->node.count, sizeof root->node, &moonfish_compare);
+	if (root->node.count > 0) qsort(root->node.children, root->node.count, sizeof root->node, &moonfish_compare);
 	moonfish_node_move(root->node.children, &root->chess, &result->move);
 	result->score = root->node.score;
 	result->node_count = root->node.visits;
--