[vtk-developers] Handling invalid vtp files

Berk Geveci berk.geveci at kitware.com
Sun Feb 14 14:01:49 EST 2010


I agree with Francois and Karthik :-)

I think that adding the assert Karthik suggested is a good idea even if we
do proper input checking in the reader. If someone calls GetTuple() with an
out-of-bounds index, the program is likely to misbehave or crash so  we
might as well let the developer (not the end-user since asserts are compiled
out in release builds) know that there is a bug somewhere.

I think that's a pre-condition. Is that right Francois?

-berk

On Sun, Feb 14, 2010 at 10:47 AM, Francois Bertel <
francois.bertel at kitware.com> wrote:

> Asserts are for programming errors ONLY. Assert check if a programming
> is valid, bug free. It is just a very basic way in C++ to implement
> Programming by Contract
> http://en.wikipedia.org/wiki/Design_by_contract (check of
> pre/post-conditions and invariants).
>
>
> They are NOT for checking the validity of the incoming data a program
> is loading or receiving. A program has to be robust regarding the
> input data (a file can be badly generated or can be corrupted because
> of a faulty block on a disk or an error in a remote connexion).
>
>
>
> On Sun, Feb 14, 2010 at 8:58 AM, Karthik Krishnan
> <karthik.krishnan at kitware.com> wrote:
> > On Sat, Feb 13, 2010 at 6:18 PM, David Doria <daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>>
> wrote:
> >> to something like:
> >> template <class T>
> >> void vtkDataArrayTemplate<T>::GetTuple(vtkIdType i, double* tuple)
> >> {
> >>   T* t = this->Array + this->NumberOfComponents*i;
> >>   if(!t)
> >>     {
> >>     return;
> >>     }
> >
> > You could change that to : assert(t != NULL)
> >
> > I think the VTK community would okay assert's. They compile only when
> > _DEBUG is defined; ie no overhead in the release version. That said,
> > Berk is right, that in this case it doesn't provide very useful
> > information..
> >
> > Mimicking some of boost's compile time and static assertion's might be
> > good for VTK, to enable bounds checking and traits validity even in
> > performance critical code.
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtk-developers
> >
> >
>
>
>
> --
> François Bertel, PhD  | Kitware Inc. Suite 204
> 1 (518) 371 3971 x113 | 28 Corporate Drive
>                      | Clifton Park NY 12065, USA
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100214/4446554a/attachment.html>


More information about the vtk-developers mailing list