Assert to bounds check MDNode::getOperand.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 8 Mar 2013 21:08:23 +0000 (21:08 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 8 Mar 2013 21:08:23 +0000 (21:08 +0000)
The getOperandPtr utility already bounds checks, but allows one-off-the-end.
This assert should catch the cases that could previously have been dereferencing
these one-off-the-end pointer. Happily, no cases of this came up with this
change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176721 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Metadata.cpp

index d751064e2227bb1ce385340be55ac489ea61967a..0228aeb31f5de51eb79a7554324ab91d3554e28f 100644 (file)
@@ -303,6 +303,7 @@ void MDNode::deleteTemporary(MDNode *N) {
 
 /// getOperand - Return specified operand.
 Value *MDNode::getOperand(unsigned i) const {
+  assert(i < getNumOperands() && "Invalid operand number");
   return *getOperandPtr(const_cast<MDNode*>(this), i);
 }