Commit faf1942f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Handle long string in vtkDataWriter.

vtkDataWriter failed to save buffer to string correctly when the string
lenght was larger than max(int). Fixed to use vtkIdType for the variable
used to store the buffer length.
parent 581ef00e
......@@ -1908,7 +1908,7 @@ vtkUnstructuredGrid *
vtkUnstructuredGrid *mergedGrid = nullptr;
int i;
int packedGridSendSize=0, packedGridRecvSize=0;
vtkIdType packedGridSendSize = 0, packedGridRecvSize = 0;
char *packedGridSend=nullptr, *packedGridRecv=nullptr;
int recvBufSize=0;
int numReceivedGrids = 0;
......@@ -2408,8 +2408,8 @@ vtkUnstructuredGrid *
vtkUnstructuredGrid **grids = new vtkUnstructuredGrid * [nprocs];
char **sendBufs = new char * [nprocs];
char **recvBufs = new char * [nprocs];
int *sendSize = new int [nprocs];
int *recvSize = new int [nprocs];
vtkIdType* sendSize = new vtkIdType[nprocs];
vtkIdType* recvSize = new vtkIdType[nprocs];
// create & pack all sub grids
......@@ -2691,7 +2691,7 @@ vtkUnstructuredGrid *vtkDistributedDataFilter::MPIRedistribute(vtkDataSet *in,
}
//-------------------------------------------------------------------------
char *vtkDistributedDataFilter::MarshallDataSet(vtkUnstructuredGrid *extractedGrid, int &len)
char* vtkDistributedDataFilter::MarshallDataSet(vtkUnstructuredGrid* extractedGrid, vtkIdType& len)
{
TimeLog timer("MarshallDataSet", this->Timing);
(void)timer;
......@@ -2726,7 +2726,7 @@ char *vtkDistributedDataFilter::MarshallDataSet(vtkUnstructuredGrid *extractedGr
}
//-------------------------------------------------------------------------
vtkUnstructuredGrid *vtkDistributedDataFilter::UnMarshallDataSet(char *buf, int size)
vtkUnstructuredGrid* vtkDistributedDataFilter::UnMarshallDataSet(char* buf, vtkIdType size)
{
TimeLog timer("UnMarshallDataSet", this->Timing);
(void)timer;
......
......@@ -466,8 +466,8 @@ private:
/**
* ?
*/
char *MarshallDataSet(vtkUnstructuredGrid *extractedGrid, int &size);
vtkUnstructuredGrid *UnMarshallDataSet(char *buf, int size);
char* MarshallDataSet(vtkUnstructuredGrid* extractedGrid, vtkIdType& size);
vtkUnstructuredGrid* UnMarshallDataSet(char* buf, vtkIdType size);
//@}
//@{
......
......@@ -2235,12 +2235,23 @@ void vtkDataWriter::CloseVTKFile(ostream *fp)
{
std::ostringstream *ostr =
static_cast<std::ostringstream*>(fp);
delete [] this->OutputString;
this->OutputStringLength = static_cast<int>(ostr->str().size());
this->OutputString = new char[this->OutputStringLength+1];
memcpy(this->OutputString, ostr->str().c_str(),
this->OutputStringLength+1);
const size_t strlength = ostr->str().size();
if (strlength > static_cast<size_t>(vtkTypeTraits<vtkIdType>::Max()))
{
this->OutputString = nullptr;
this->OutputStringLength = 0;
vtkErrorMacro("OutputStringLength overflow: the length of data in the "
"writer is greater than what would fit in a variable of type "
"`vtkIdType`. You may have to recompile with VTK_USE_64BIT_IDS."
"Presently, vtkIdType is " << sizeof(vtkIdType) * 8 << " bits.");
}
else
{
this->OutputStringLength = static_cast<vtkIdType>(strlength);
this->OutputString = new char[strlength + 1];
}
memcpy(this->OutputString, ostr->str().c_str(), this->OutputStringLength + 1);
}
delete fp;
}
......
......@@ -77,7 +77,7 @@ public:
* and can be retrieved with these methods. The string is deleted during
* the next call to write ...
*/
vtkGetMacro(OutputStringLength, int);
vtkGetMacro(OutputStringLength, vtkIdType);
vtkGetStringMacro(OutputString);
unsigned char *GetBinaryOutputString()
{
......@@ -294,7 +294,7 @@ protected:
int WriteToOutputString;
char *OutputString;
int OutputStringLength;
vtkIdType OutputStringLength;
void WriteData() override; //dummy method to allow this class to be instantiated and delegated to
......
......@@ -551,7 +551,7 @@ int vtkCommunicator::MarshalDataObject(vtkDataObject *object,
vtkGenericWarningMacro("Error detected while marshaling data object.");
return 0;
}
unsigned int size = writer->GetOutputStringLength();
const vtkIdType size = writer->GetOutputStringLength();
if (object->GetExtentType() == VTK_3D_EXTENT)
{
// You would think that the extent information would be properly saved, but
......
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