The International Simutrans Forum

 

Author Topic: Fix for possible crash when building multi-tile buildings  (Read 463 times)

0 Members and 1 Guest are viewing this topic.

Offline ceeac

  • Devotee
  • *
  • Posts: 256
Fix for possible crash when building multi-tile buildings
« on: July 07, 2020, 06:57:13 AM »
This fixes an OOB array access when failing to upgrade city buildings from single-tile to multi-tile ones.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Fix for possible crash when building multi-tile buildings
« Reply #1 on: July 09, 2020, 10:48:49 AM »
Not played around a lot with this section of code but think that maybe this code in trunk
Code: [Select]
static koord const area3x3[] = {
    koord( 0, 1),  //  1x2
    koord( 1, 0),  //  2x1
    koord( 1, 1),  //  2x2
    koord( 2, 0),  //  3x1
    koord( 2, 1),  //  3x2
    koord( 0, 2),  //  1x3
    koord( 2, 2)   //  3x3
};
should be
Code: [Select]
static koord const area3x3[] = {
    koord( 0, 1),  //  1x2
    koord( 1, 0),  //  2x1
    koord( 1, 1),  //  2x2
    koord( 2, 0),  //  3x1
    koord( 2, 1),  //  3x2
    koord( 0, 2),  //  1x3
    koord( 1, 2),  //  2x3
    koord( 2, 2)   //  3x3
};

This would fix the potential array out of bounds also. Although you might still want to replace 8 with lengthof to provide extra protection.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: Fix for possible crash when building multi-tile buildings
« Reply #2 on: July 09, 2020, 02:45:23 PM »
I think indeed the missing koord is needed to function properly, but lengthof is a good idea too ...

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Fix for possible crash when building multi-tile buildings
« Reply #3 on: July 09, 2020, 03:12:31 PM »
Committed in 9163 - many thanks ceeac