legacyclonk / LegacyClonk

The LegacyClonk engine and the c4group command line tool.
https://clonkspot.org/lc-en
Other
83 stars 18 forks source link

Engine crash when building objects without mass #96

Closed Remus76 closed 1 year ago

Remus76 commented 1 year ago

The construction process of an object which has Mass=0 set in DefCore leads to an engine crash due to an unsecure division by this value in C4Object::Build. Same holds for leaving this value out of DefCore because 0 is the default then. I found such objects on CCAN so this could happen in real world scenarios.

Though I don't know the code style guidelines very well this can be fixed by using

const int32_t nonzeroMass = Def->Mass ? Def->Mass : 1;
DoCon(iLevel * iBuildSpeed * 150 / nonzeroMass, false, fNeedMaterial);

instead of https://github.com/legacyclonk/LegacyClonk/blob/master/src/C4Object.cpp#L1734 without breaking anything because

The fix is just a suggestion from my side. You can use any other value (or maybe something else?).