diff --git a/reach/README.md b/reach/README.md index 39a41185..8fb449f9 100644 --- a/reach/README.md +++ b/reach/README.md @@ -85,9 +85,6 @@ stdout if no path was given. Under `lib/`: - json.hpp + open-source (MIT) JSON library from https://github.com/nlohmann/json -- cache.hpp - + templated helper functions for reading/writing data structures - (vector, unordered_set, unordered_map) to/from disk - facts.hpp, facts.cpp + in-memory representation of fact databases, and loading from .facts files + defns related to dlsym loaded symbol logs from dynamic analysis diff --git a/reach/lib/binary_heap.hpp b/reach/lib/binary_heap.hpp index 74b78695..57597582 100644 --- a/reach/lib/binary_heap.hpp +++ b/reach/lib/binary_heap.hpp @@ -8,6 +8,11 @@ // Use this instead of std::priority_queue for fast 'contains' and // 'decrease_key' operations. +// 0-indexed heap: +// 0 +// 1 2 +// 3 4 5 6 + #pragma once #include @@ -31,11 +36,18 @@ class binary_heap { // Extract the minimum element from the heap. std::pair extract() { + if (_heap.empty()) { + throw std::out_of_range("extract on empty heap"); + } const auto root = this->_heap.front(); - this->_heap[0] = this->_heap.back(); - this->_heap.pop_back(); this->_ixs.erase(root.first); + if (this->_heap.size() == 1) { + this->_heap.pop_back(); + return root; + } + this->_heap[0] = this->_heap.back(); this->_ixs[this->_heap[0].first] = 0; + this->_heap.pop_back(); this->_heapify_down(0); return root; } @@ -69,7 +81,7 @@ class binary_heap { // Heapify up at index [i]. void _heapify_up(size_t i) { if (i > 0) { - size_t parent_i = i / 2; + size_t parent_i = (i - 1) / 2; if (this->_heap[i].second < this->_heap[parent_i].second) { this->_swap(i, parent_i); this->_heapify_up(parent_i); @@ -79,8 +91,8 @@ class binary_heap { // Heapify down at index [i]. void _heapify_down(size_t i) { - size_t left_i = 2 * i; - size_t right_i = 2 * i + 1; + size_t left_i = 2 * i + 1; + size_t right_i = 2 * i + 2; size_t smallest = i; if (left_i < this->_heap.size() && diff --git a/reach/src/main.cpp b/reach/src/main.cpp index 05429bcd..4124763a 100644 --- a/reach/src/main.cpp +++ b/reach/src/main.cpp @@ -132,8 +132,6 @@ int main(int argc, char* argv[]) { .flag(); program.add_argument("-ds", "--dlsym-log") .help("path to file containing dlsym log of loaded symbols"); - program.add_argument("-o", "--output") - .help("JSON output path"); program.add_argument("-g", "--graph") .help("graph type (\"simple\", \"cfg\", or \"call\"). Default \"cfg\""); program.add_argument("-n", "--num-paths")