[vtkusers] Just plain wrong

Adam D. Burry aburry at igotechnologies.com
Wed Dec 5 21:17:47 EST 2001


Hi:

This code from vtk-3.2 is just plain wrong. There is an argument on
technical grounds that it is ok, but morally: it is always wrong:

	void vtkStructuredGrid::CopyStructure(vtkDataSet *ds)
	{
		vtkStructuredGrid *sg=(vtkStructuredGrid *)ds;
		// ...

At the very least it would be better written as:

	void vtkStructuredGrid::CopyStructure(vtkDataSet *ds)
	{
		vtkStructuredGrid* sg = dynamic_cast<vtkStructuredGrid*>( ds );
		if ( 0 == ds )
		{
			vtkErrorMacro( << "Type mismatch in CopyStructure." );
		}
		// ...

Even better, assuming this method must be different from an assignment
operator or a copy constructor, would be:

	void vtkStructuredGrid::CopyStructure(vtkStructuredGrid* ds)
	{
		// ...

The problem, if it is not clear from the code, is that the vtk-3.2 code
is forcing a downcast that is not necessarily safe. So if you are using
CopyStructure(), be careful.

Adam

--
Mr. Adam D. Burry, Software Developer
aburry at igotechnologies.com



More information about the vtkusers mailing list