#45893: city_create_unit() segfaults when punit is null Open Date: 2022-10-17 14:58 Last Update: 2023-06-09 01:36 URL for this Ticket: https://osdn.net//projects/freeciv/ticket/45893 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=45893 --------------------------------------------------------------------- Last Changes/Comment on this Ticket: 2023-06-09 01:36 Updated by: cazfi * Owner Update from (None) to cazfi * Resolution Update from None to Accepted * Milestone Update from (None) to 3.1.0-beta3 * Component Update from (None) to Server * Type Update from Bugs to Patches Comment: Reply To cazfi Those cases with multiple build slots producing NULL units seem like result of FCW specific bugs #45894 and #45895 Attached patch gives those parameters nonnull attribute, to make it likely that in the future such bugs get caught as soon as they get created. --------------------------------------------------------------------- Ticket Status: Reporter: (Anonymous) Owner: cazfi Type: Patches Status: Open [Owner assigned] Priority: 5 - Medium MileStone: 3.1.0-beta3 Component: Server Severity: 5 - Medium Resolution: Accepted --------------------------------------------------------------------- Ticket details: This wasn't caught before because it's very rare. However, there may be ways to get units which are null in some situations like multiple build slots, etc. FCW server experienced it and had to fix it. static struct unit *city_create_unit(struct city *pcity, const struct unit_type *utype) { if (!pcity || !utype) return NULL; // 17Oct2022 attempt to avoid segfault struct player *pplayer = city_owner(pcity); struct unit *punit; int saved_unit_id; city_production_unit_veteran_level(pcity, utype), pcity->id, 0); pplayer->score.units_built++; if (!punit) { notify_conn(game.est_connections, city_tile(pcity), E_WONDER_WILL_BE_BUILT, ftc_server, _("Notice: %s in %s creating illegal segfault. Report to admin immediately!"), utype_name_translation(utype), city_link(pcity)); return NULL; // 17Oct2022 line below was segfault: } saved_unit_id = punit->id; -- Ticket information of Freeciv project Freeciv Project is hosted on OSDN Project URL: https://osdn.net/projects/freeciv/ OSDN: https://osdn.net URL for this Ticket: https://osdn.net/projects/freeciv/ticket/45893 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=45893