Commit 631d795b authored by Kevin H. Hobbs's avatar Kevin H. Hobbs
Browse files

Reads past EOF are expected

The vtk3DSImporter reports errors like :

ERROR: In /home/kevin/kitware/VTK/IO/Import/vtk3DSImporter.cxx, line
1083
vtk3DSImporter (0x75cd20): Pre-mature end of file in read_word

on almost every machine in the dashboard.

I did a bit of poking around with gdb and std::cerr, and it looks like
these reads past the end of the file are not at all unexpected.

For example parse_face_array uses read_word to read the number of faces
and then to read what I assume are the face vertex ids: a failure here
is catastrophic.

Then even though importer->GetFileFD() could be at the end of the file
it calls start_chunk which calls both read_word and read_dword to see if
there is another (sub?)chunk to parse into.

This commit adds two new functions peek_word and peek_dword that are
exactly like read_word and read_dword except that they do not report an
error when they read past the end of the file.

peek_word and peek_dword replace read_word and read_dword in start_chunk
where the read past the end of the file is not an error.

read_dword is now unused

Because read_dword is now unused, it should be removed.

Stop leaking render windows

Hopefully X and Mesa have advanced to the point where we can delete the
render window without error.

If any tested configurations still have trouble let us work around them
more precisely.

Change-Id: I90a68d1241379886d38d150ba00816d869c6675f
parent 004944f0
......@@ -52,14 +52,14 @@ viewer.SetColorWindow(255)
viewer.SetColorLevel(127.5)
viewer.Render()
# on several opengl X window unix implementations
# multiple context deletes cause errors
# so we leak the renWin in this test for unix
if renWin1.IsA('vtkXOpenGLRenderWindow'):
renWin1.Register(ren1)
dl = vtk.vtkDebugLeaks()
dl.SetExitError(0)
del dl
## on several opengl X window unix implementations
## multiple context deletes cause errors
## so we leak the renWin in this test for unix
#if renWin1.IsA('vtkXOpenGLRenderWindow'):
# renWin1.Register(ren1)
# dl = vtk.vtkDebugLeaks()
# dl.SetExitError(0)
# del dl
# iren.Initialize()
# iren.Start()
......@@ -52,14 +52,14 @@ viewer.SetColorWindow(255)
viewer.SetColorLevel(127.5)
viewer.Render()
# on several opengl X window unix implementations
# multiple context deletes cause errors
# so we leak the renWin1 in this test for unix
if renWin1.IsA('vtkXOpenGLRenderWindow'):
renWin1.Register(ren1)
dl = vtk.vtkDebugLeaks()
dl.SetExitError(0)
del dl
## on several opengl X window unix implementations
## multiple context deletes cause errors
## so we leak the renWin1 in this test for unix
#if renWin1.IsA('vtkXOpenGLRenderWindow'):
# renWin1.Register(ren1)
# dl = vtk.vtkDebugLeaks()
# dl.SetExitError(0)
# del dl
# iren.Initialize()
# iren.Start()
......@@ -49,12 +49,12 @@ vtkImageViewer viewer
viewer SetColorLevel 127.5
viewer Render
# on several opengl X window unix implementations
# multiple context deletes cause errors
# so we leak the renWin1 in this test for unix
if { $tcl_platform(platform) == "unix" } {
renWin1 Register ren1
vtkDebugLeaks dl
dl SetExitError 0
dl Delete
}
## on several opengl X window unix implementations
## multiple context deletes cause errors
## so we leak the renWin1 in this test for unix
#if { $tcl_platform(platform) == "unix" } {
# renWin1 Register ren1
# vtkDebugLeaks dl
# dl SetExitError 0
# dl Delete
#}
......@@ -49,12 +49,12 @@ vtkImageViewer viewer
viewer SetColorLevel 127.5
viewer Render
# on several opengl X window unix implementations
# multiple context deletes cause errors
# so we leak the renWin1 in this test for unix
if { $tcl_platform(platform) == "unix" } {
renWin1 Register ren1
vtkDebugLeaks dl
dl SetExitError 0
dl Delete
}
## on several opengl X window unix implementations
## multiple context deletes cause errors
## so we leak the renWin1 in this test for unix
#if { $tcl_platform(platform) == "unix" } {
# renWin1 Register ren1
# vtkDebugLeaks dl
# dl SetExitError 0
# dl Delete
#}
......@@ -96,7 +96,8 @@ static void start_chunk (vtk3DSImporter *importer, vtk3DSChunk *chunk);
static void end_chunk (vtk3DSImporter *importer, vtk3DSChunk *chunk);
static byte read_byte (vtk3DSImporter *importer);
static word read_word (vtk3DSImporter *importer);
static dword read_dword (vtk3DSImporter *importer);
static word peek_word (vtk3DSImporter *importer);
static dword peek_dword (vtk3DSImporter *importer);
static float read_float (vtk3DSImporter *importer);
static void read_point (vtk3DSImporter *importer, vtk3DSVector v);
static char *read_string (vtk3DSImporter *importer);
......@@ -1043,8 +1044,8 @@ static float parse_float_percentage(vtk3DSImporter *importer)
static void start_chunk (vtk3DSImporter *importer, vtk3DSChunk *chunk)
{
chunk->start = ftell(importer->GetFileFD());
chunk->tag = read_word(importer);
chunk->length = read_dword(importer);
chunk->tag = peek_word(importer);
chunk->length = peek_dword(importer);
if (chunk->length == 0)
{
chunk->length = 1;
......@@ -1083,14 +1084,24 @@ static word read_word(vtk3DSImporter *importer)
return data;
}
static dword read_dword(vtk3DSImporter *importer)
static word peek_word(vtk3DSImporter *importer)
{
word data;
if (fread (&data, 2, 1, importer->GetFileFD()) != 1)
{
data = 0;
}
vtkByteSwap::Swap2LE ((short *) &data);
return data;
}
static dword peek_dword(vtk3DSImporter *importer)
{
dword data;
if (fread (&data, 4, 1, importer->GetFileFD()) != 1)
{
vtkErrorWithObjectMacro(
importer, "Pre-mature end of file in read_dword\n");
data = 0;
}
......@@ -1098,7 +1109,6 @@ static dword read_dword(vtk3DSImporter *importer)
return data;
}
static float read_float(vtk3DSImporter *importer)
{
float data;
......
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