Skip to content

Commit

Permalink
check state object are not null before using it. For alternate weight…
Browse files Browse the repository at this point in the history
…s setting where some feature functions are not used for a particular sentence
  • Loading branch information
hieuhoang committed Jan 17, 2019
1 parent 26940e7 commit 49b388a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions moses/Hypothesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,11 @@ size_t Hypothesis::hash() const
// states
for (size_t i = 0; i < m_ffStates.size(); ++i) {
const FFState *state = m_ffStates[i];
size_t hash = state->hash();
boost::hash_combine(seed, hash);

if (state) {
size_t hash = state->hash();
boost::hash_combine(seed, hash);
}
}
return seed;
}
Expand All @@ -430,10 +433,15 @@ bool Hypothesis::operator==(const Hypothesis& other) const

// states
for (size_t i = 0; i < m_ffStates.size(); ++i) {
const FFState &thisState = *m_ffStates[i];
const FFState &otherState = *other.m_ffStates[i];
if (thisState != otherState) {
return false;
const FFState *thisState = m_ffStates[i];

if (thisState) {
const FFState *otherState = other.m_ffStates[i];
assert(otherState);

if ((*thisState) != (*otherState)) {
return false;
}
}
}
return true;
Expand Down

0 comments on commit 49b388a

Please sign in to comment.