News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

Fix for possible crash when building multi-tile buildings

Started by ceeac, July 07, 2020, 06:57:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ceeac

This fixes an OOB array access when failing to upgrade city buildings from single-tile to multi-tile ones.

kierongreen

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.

prissi

I think indeed the missing koord is needed to function properly, but lengthof is a good idea too ...

kierongreen