Compare nullness in Hypothesis::RecombineCompare.

The comparison code subtracted two pointers in the case where at least one
was null, to get a signed int comparison result.  But that subtraction is
undefined, and the cast to int (dropping the most-significant bits!) made the
outcome even less uncertain.

In this patch I compare the nullness of the pointers instead, which should
always return a well-defined -1, 0, or 1.
This commit is contained in:
Jeroen Vermeulen 2015-07-16 16:48:20 +07:00
parent 0ca2bcb28d
commit d4508e984f

View File

@ -213,7 +213,8 @@ RecombineCompare(const Hypothesis &compare) const
for (unsigned i = 0; i < m_ffStates.size(); ++i) {
if (m_ffStates[i] == NULL || compare.m_ffStates[i] == NULL) {
comp = m_ffStates[i] - compare.m_ffStates[i];
// TODO: Can this situation actually occur?
comp = int(m_ffStates[i] != NULL) - int(compare.m_ffStates[i] != NULL);
} else {
comp = m_ffStates[i]->Compare(*compare.m_ffStates[i]);
}