Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions reach/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions reach/lib/binary_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ class binary_heap {

// Extract the minimum element from the heap.
std::pair<K, V> 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;
}
Expand Down Expand Up @@ -69,7 +76,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);
Expand All @@ -79,8 +86,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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here to explain the indexing structure? I'm fond of ascii art so a graph like this makes sense to me, but choose what you feel is best.

       0
   1       2
 3   4   5    6

Is it supposed to be index i is at i and its children are at 2i +1, 2i+2? I guess this is the result of 0-indexing instead of 1-indexing as the old version would have worked before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the top of the file. Honestly, I would rather avoid using a custom binary heap implementation. I just threw this in because I had it lying around.

size_t right_i = 2 * i + 2;

size_t smallest = i;
if (left_i < this->_heap.size() &&
Expand Down
2 changes: 0 additions & 2 deletions reach/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this argument removed? Fairly certain it is still used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still there. This removed the second redundant call to add_argument for the --output argument.

.help("JSON output path");
program.add_argument("-g", "--graph")
.help("graph type (\"simple\", \"cfg\", or \"call\"). Default \"cfg\"");
program.add_argument("-n", "--num-paths")
Expand Down