add: prevent saving graph with less than eight nodes

this is done to prevent crashes in A* pathfinder when there is less than `max  node links` nodes available to work with.

loading of such graphs was disabled sometime ago, and saving wasn't, my bad.
This commit is contained in:
jeefo 2023-03-24 14:33:04 +03:00
commit a46e64f27e
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED

View file

@ -1597,6 +1597,12 @@ bool BotGraph::convertOldFormat () {
template <typename U> bool BotGraph::saveStorage (StringRef ext, StringRef name, StorageOption options, StorageVersion version, const SmallArray <U> &data, ExtenHeader *exten) {
bool isGraph = !!(options & StorageOption::Graph);
// do not allow to save graph with less than 8 nodes
if (isGraph && length () < kMaxNodeLinks) {
ctrl.msg ("Can't save graph data with less than %d nodes. Please add some more before saving.", kMaxNodeLinks);
return false;
}
String filename;
filename.assignf ("%s.%s", game.getMapName (), ext).lowercase ();