Commit bc424e27 authored by Kyle Lutz's avatar Kyle Lutz
Browse files

Add asserts to vtkDataArrayTemplate Set/GetValue()

This adds asserts which will trigger when invalid indices are
pass to the GetValue() and SetValue() methods in the
vtkDataArrayTemplate class. This causes tests which access invalid
elements of a vtkDataArray to fail with an assert. Previously these
types of errors would only be found by valgrind.

Change-Id: I0bfc7de1453c871b55cfe87fba43f9095684fbee
parent e07e9824
......@@ -23,6 +23,7 @@
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkDataArray.h"
#include <cassert> // for assert()
template <class T>
class vtkDataArrayTemplateLookup;
......@@ -131,13 +132,14 @@ public:
// Description:
// Get the data at a particular index.
T GetValue(vtkIdType id) { return this->Array[id]; }
T GetValue(vtkIdType id)
{ assert(id >= 0 && id < this->Size); return this->Array[id]; }
// Description:
// Set the data at a particular index. Does not do range checking. Make sure
// you use the method SetNumberOfValues() before inserting data.
void SetValue(vtkIdType id, T value)
{ this->Array[id] = value;};
{ assert(id >= 0 && id < this->Size); this->Array[id] = value;};
// Description:
// Specify the number of values for this object to hold. Does an
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment