Bug #2179
openServer segfault when city cannot provide goods
0%
Description
Supplied rulesets are OK, but a clumsy custom ruleset author can make a game.ruleset goods section such that it may sometimes be impossible for a city to provide any goods. In that case, routine goods_from_city_to_unit() returns NULL, and some places in the code down the line that depend on it are not checking.
This patch prevents crashing, but I'm not entirely happy about the resulting situation. That poor good-less trade unit will likely never be able to "Enter Marketplace" nor "Establish Trade Route", and its owner (human or AI) will have no clue why. Could still do "Help Wonder" or "Disband Unit Recover". I thought of an alternate solution - instead of returning NULL, have goods_from_city_to_unit() return a pointer to a static struct goods_type called default_goods, but that is problematic. That good would not be in the ruleset but might have the same name, the struct's id would have to be outside the legal range, and I don't know any way to construct a struct requirement_vector for it.
Another alternate solution that I think would not be workable is to check at ruleset loading time that cities can always provide goods.
Files
Updated by Dean Brown 1 day ago
- File 2179_Main.patch 2179_Main.patch added
- File 2179_S3_3.patch 2179_S3_3.patch added