Commit 725a453f authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

vtkArrayExtents::GetSize() and vtkArray::GetSize() return vtkTypeUInt64.

This reduces the likelihood of overflow when computing the result for
GetSize().
parent 96104c4c
......@@ -91,6 +91,7 @@ IF(VTK_USE_N_WAY_ARRAYS)
TestArrayExtents.cxx
TestArrayUserTypes.cxx
TestArrayVariants.cxx
TestArraySize.cxx
TestSparseArrayValidation.cxx
EXTRA_INCLUDE vtkTestDriver.h
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayAPI.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkDenseArray.h>
#include <vtkSmartPointer.h>
#include <vtkSparseArray.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#define test_expression(expression) \
{ \
if(!(expression)) \
{ \
std::ostringstream buffer; \
buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
throw std::runtime_error(buffer.str()); \
} \
}
int TestArraySize(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
try
{
// Test to see that array sizes don't overflow ...
vtkSmartPointer<vtkSparseArray<double> > array = vtkSmartPointer<vtkSparseArray<double> >::New();
array->Resize(1200000, 18000);
test_expression(array->GetSize() == 21600000000);
return 0;
}
catch(std::exception& e)
{
cerr << e.what() << endl;
return 1;
}
}
......@@ -2,7 +2,7 @@
Program: Visualization Toolkit
Module: vtkArray.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
......@@ -50,15 +50,15 @@ void vtkArray::PrintSelf(ostream &os, vtkIndent indent)
Superclass::PrintSelf(os, indent);
os << indent << "Name: " << this->Name << endl;
os << indent << "Dimensions: " << this->GetDimensions() << endl;
os << indent << "Extents: " << this->GetExtents() << endl;
os << indent << "DimensionLabels:";
for(vtkIdType i = 0; i != this->GetDimensions(); ++i)
os << " " << this->GetDimensionLabel(i);
os << endl;
os << indent << "Size: " << this->GetSize() << endl;
os << indent << "NonNullSize: " << this->GetNonNullSize() << endl;
}
......@@ -168,7 +168,7 @@ void vtkArray::Resize(const vtkArrayRange& i, const vtkArrayRange& j, const vtkA
}
void vtkArray::Resize(const vtkArrayExtents& extents)
{
{
this->InternalResize(extents);
}
......@@ -182,7 +182,7 @@ vtkIdType vtkArray::GetDimensions()
return this->GetExtents().GetDimensions();
}
vtkIdType vtkArray::GetSize()
vtkTypeUInt64 vtkArray::GetSize()
{
return this->GetExtents().GetSize();
}
......@@ -193,7 +193,7 @@ void vtkArray::SetName(const vtkStdString& raw_name)
vtkStdString name(raw_name);
name.erase(vtkstd::remove(name.begin(), name.end(), '\r'), name.end());
name.erase(vtkstd::remove(name.begin(), name.end(), '\n'), name.end());
this->Name = name;
}
......@@ -228,5 +228,3 @@ vtkStdString vtkArray::GetDimensionLabel(vtkIdType i)
return this->InternalGetDimensionLabel(i);
}
......@@ -128,7 +128,7 @@ public:
// extents. This is equal to the number of values stored in a dense
// array, but may be larger than the number of values stored in a
// sparse array.
vtkIdType GetSize();
vtkTypeUInt64 GetSize();
// Description:
// Returns the number of non-null values stored in the array. Note
......
......@@ -97,12 +97,12 @@ vtkIdType vtkArrayExtents::GetDimensions() const
return this->Storage.size();
}
vtkIdType vtkArrayExtents::GetSize() const
vtkTypeUInt64 vtkArrayExtents::GetSize() const
{
if(this->Storage.empty())
return 0;
vtkIdType size = 1;
vtkTypeUInt64 size = 1;
for(size_t i = 0; i != this->Storage.size(); ++i)
size *= this->Storage[i].GetSize();
......
......@@ -113,7 +113,7 @@ public:
// Return the number of values that *could* be stored using the
// current extents. This is equal to the product of the size of the
// extent along each dimension.
vtkIdType GetSize() const;
vtkTypeUInt64 GetSize() const;
// Description:
// Set the current number of dimensions. Note that this method
......
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