1
0

Merge pull request #2018 from mc-server/ProbDif

Fixed possible crash in cProbabDistrib
This commit is contained in:
Mattes D 2015-05-14 17:23:23 +02:00
commit c3804f08c8

View File

@ -133,6 +133,7 @@ int cProbabDistrib::MapValue(int a_OrigValue) const
// Linearly interpolate between Lo and Hi:
int ProbDif = m_Cumulative[Hi].m_Probability - m_Cumulative[Lo].m_Probability;
ProbDif = (ProbDif != 0) ? ProbDif : 1;
int ValueDif = m_Cumulative[Hi].m_Value - m_Cumulative[Lo].m_Value;
return m_Cumulative[Lo].m_Value + (a_OrigValue - m_Cumulative[Lo].m_Probability) * ValueDif / ProbDif;
}