Fix potential segfault

This commit is contained in:
Alayan
2018-10-07 16:29:18 +02:00
parent 767b613389
commit 9b6156279c
2 changed files with 21 additions and 16 deletions

View File

@@ -115,9 +115,10 @@ int Achievement::computeFullfiledGoals(AchievementInfo::goalTree &progress, Achi
return goals_completed;
}
}
else if (progress.children[0].type == "AND" ||
progress.children[0].type == "AND-AT-ONCE" ||
progress.children[0].type == "OR")
else if (progress.children.size() == 1 &&
(progress.children[0].type == "AND" ||
progress.children[0].type == "AND-AT-ONCE" ||
progress.children[0].type == "OR"))
{
return computeFullfiledGoals(progress.children[0], reference.children[0]);
}
@@ -125,7 +126,7 @@ int Achievement::computeFullfiledGoals(AchievementInfo::goalTree &progress, Achi
{
return (recursiveCompletionCheck(progress.children[0], reference.children[0])) ? 1 : 0;
}
} // recursiveGoalCount
} // computeFullfiledGoals
// ----------------------------------------------------------------------------
/** Returns how much of an achievement has been achieved in the form n/m.
@@ -189,9 +190,10 @@ int Achievement::computeGoalProgress(AchievementInfo::goalTree &progress, Achiev
}
return progress.value;
}
else if (progress.children[0].type == "AND" ||
progress.children[0].type == "AND-AT-ONCE" ||
progress.children[0].type == "OR")
else if (progress.children.size() == 1 &&
(progress.children[0].type == "AND" ||
progress.children[0].type == "AND-AT-ONCE" ||
progress.children[0].type == "OR"))
{
return computeGoalProgress(progress.children[0], reference.children[0]);
}

View File

@@ -166,9 +166,10 @@ int AchievementInfo::getRecursiveDepth(goalTree &parent)
}
return max+1;
}
else if (parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR")
else if (parent.children.size() == 1 &&
(parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR"))
{
return getRecursiveDepth(parent.children[0]);
}
@@ -195,9 +196,10 @@ int AchievementInfo::recursiveGoalCount(goalTree &parent)
else
return m_goal_tree.children.size();
}
else if (parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR")
else if (parent.children.size() == 1 &&
(parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR"))
{
return recursiveGoalCount(parent.children[0]);
}
@@ -221,9 +223,10 @@ int AchievementInfo::recursiveProgressCount(goalTree &parent)
{
return -1; // signal that this is invalid.
}
else if (parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR")
else if (parent.children.size() == 1 &&
(parent.children[0].type == "AND" ||
parent.children[0].type == "AND-AT-ONCE" ||
parent.children[0].type == "OR"))
{
return recursiveGoalCount(parent.children[0]);
}