Fix infinite loop in dictGetHierarchy if id chain looped

This commit is contained in:
proller 2017-08-04 19:59:50 +03:00 committed by alexey-milovidov
parent 7937903d56
commit 6ca798a357
2 changed files with 13 additions and 1 deletions

View File

@ -138,6 +138,11 @@ void CacheDictionary::isInImpl(
out[out_idx] = 1;
}
/// Found intermediate parent, add this value to search at next loop iteration
else if (children[new_children_idx] == parents[parents_idx])
{
// Loop detected
out[out_idx] = 0;
}
else
{
children[new_children_idx] = parents[parents_idx];

View File

@ -1431,9 +1431,16 @@ private:
if (0 == id)
continue;
auto & hierarchy = hierarchies[i];
//Checking for loop
if (std::find(std::begin(hierarchy), std::end(hierarchy), id) != std::end(hierarchy))
continue;
all_zeroes = false;
/// place id at it's corresponding place
hierarchies[i].push_back(id);
hierarchy.push_back(id);
++total_count;
}