Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for CountAvailablePredicates that prevents out of range access of the input. #169

Merged
merged 1 commit into from
Dec 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/engine/CountAvailablePredicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ void CountAvailablePredicates::computePatternTrick(
size_t posInput = 0;
Id lastSubject = ID_NO_VALUE;
while (posInput < input->size()) {
while ((*input)[posInput][subjectColumn] == lastSubject &&
posInput < input->size()) {
// Skip over elements with the same subject (don't count them twice)
if ((*input)[posInput][subjectColumn] == lastSubject) {
posInput++;
continue;
}
size_t subject = (*input)[posInput][subjectColumn];
lastSubject = subject;
Expand Down Expand Up @@ -254,12 +255,14 @@ void CountAvailablePredicates::computePatternTrick(
}
posInput++;
}
// resolve the patterns to predicate counts
for (const auto& it : patternCounts) {
std::pair<Id*, size_t> pattern = patterns[it.first];
for (size_t i = 0; i < pattern.second; i++) {
predicateCounts[pattern.first[i]] += it.second;
}
}
// write the predicate counts to the result
result->reserve(predicateCounts.size());
for (const auto& it : predicateCounts) {
result->push_back(array<Id, 2>{it.first, static_cast<Id>(it.second)});
Expand Down