The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: ceeac on July 07, 2020, 06:57:13 AM

Title: Fix for possible crash when building multi-tile buildings
Post by: ceeac 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.
Title: Re: Fix for possible crash when building multi-tile buildings
Post by: kierongreen 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
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

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.
Title: Re: Fix for possible crash when building multi-tile buildings
Post by: prissi 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 ...
Title: Re: Fix for possible crash when building multi-tile buildings
Post by: kierongreen on July 09, 2020, 03:12:31 PM
Committed in 9163 - many thanks ceeac