diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2019-05-14 12:23:41 -0400 |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2019-05-14 14:00:13 -0400 |
commit | dfa24355eacbf99cf98bbf4027b8188c13ac7154 (patch) | |
tree | 971b935dc17e9c470cf34cada4215bfc49e18994 | |
parent | a9837130cdda163225367aaed51d66ba4d924e34 (diff) | |
download | cmake-dfa24355eacbf99cf98bbf4027b8188c13ac7154.tar.gz |
cmUVProcessChain: Add assert() for static analysis tools
Some static analysis tools throw a false positive for an
out-of-bounds item that is being dereferenced. This out-of-bounds
error will never actually happen because of how
cmUVProcessChain::InternalData::AddCommand() is being called.
Nevertheless, this change adds an assert() to help static analysis
tools be absolutely certain that the referenced item is within the
vector's bounds.
This change also changes the item access to use an index rather
than an iterator.
-rw-r--r-- | Source/cmUVProcessChain.cxx | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx index c4e30d4fc3..90ece0bc50 100644 --- a/Source/cmUVProcessChain.cxx +++ b/Source/cmUVProcessChain.cxx @@ -8,6 +8,8 @@ #include "cmUVStreambuf.h" #include "cm_uv.h" +#include <assert.h> + #include <iterator> #include <memory> #include <utility> @@ -250,7 +252,8 @@ bool cmUVProcessChain::InternalData::AddCommand( if (first) { stdio[0].flags = UV_IGNORE; } else { - auto& prev = **std::prev(this->Processes.end(), 2); + assert(this->Processes.size() >= 2); + auto& prev = *this->Processes[this->Processes.size() - 2]; stdio[0].flags = UV_INHERIT_STREAM; stdio[0].data.stream = prev.OutputPipe; } |