Skip to content

Commit

Permalink
Explicitly use std::deque for the missing node handler stack:
Browse files Browse the repository at this point in the history
We need to ensure that pointers and/or references to existing
elements will not be invalidated during the course of element
insertion and removal.

Containers like std::vector do not offer this guarantee, and
cannot be used as the underlying container for the stack.

By choosing to explicitly specify std::deque as the underlying
cotnainer, we avoid:

- the unlikely possibility of the C++ standards committee
  changing the default template parameter to a container;
- the more likely possibility of an accidental change by
  a programmer, without fully considering the consequences.
  • Loading branch information
nbougalis authored and bachase committed Nov 29, 2017
1 parent c11e186 commit f0e1024
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ripple/shamap/SHAMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ class SHAMap
int, // while child we check first
int, // which child we check next
bool>; // whether we've found any missing children yet
std::stack <StackEntry> stack_;

// We explicitly choose to specify the use of std::deque here, because
// we need to ensure that pointers and/or references to existing elements
// will not be invalidated during the course of element insertion and
// removal. Containers that do not offer this guarantee, such as
// std::vector, can't be used here.
std::stack <StackEntry, std::deque<StackEntry>> stack_;

// nodes we may acquire from deferred reads
std::vector <std::tuple <SHAMapInnerNode*, SHAMapNodeID, int>> deferredReads_;
Expand Down

0 comments on commit f0e1024

Please sign in to comment.