Skip to content

Commit 336cf57

Browse files
committed
BUG: fixed valgrind defect in FreeSurfer mesh test
In itkFreeSurferMeshIOTest.cxx updated the order of calls to avoid uninitialized memory defect. Also removed Read/WritePointData because there is no test file. #3772
1 parent bd4d46e commit 336cf57

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

Modules/IO/MeshFreeSurfer/test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ itk_add_test(NAME itkFreeSurferMeshIOTestAscii
1313
${ITK_TEST_OUTPUT_DIR}/fsmeshiosphere.fsa
1414
DATA{Baseline/sphere.fsb}
1515
${ITK_TEST_OUTPUT_DIR}/fsa2fsbsphere.fsb
16-
0 1 1 1 1 162 0 320 0 0
16+
0 0 0 0 0 162 0 320 0 0
1717
)
1818
itk_add_test(NAME itkFreeSurferMeshIOTestBinary
1919
COMMAND ITKIOMeshFreeSurferTestDriver itkFreeSurferMeshIOTest
2020
DATA{Baseline/sphere.fsb}
2121
${ITK_TEST_OUTPUT_DIR}/fsmeshiosphere.fsb
2222
DATA{Baseline/sphere.fsa}
2323
${ITK_TEST_OUTPUT_DIR}/fsb2fsasphere.fsa
24-
0 1 1 1 1 162 0 320 0 1
24+
0 0 0 0 0 162 0 320 0 1
2525
)
2626
itk_add_test(NAME itkMeshFileReadWriteTestFreeSurfer1
2727
COMMAND ITKIOMeshFreeSurferTestDriver itkMeshFileReadWriteTest

Modules/IO/MeshFreeSurfer/test/itkFreeSurferMeshIOTest.cxx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,59 +73,42 @@ itkFreeSurferMeshIOTestHelper(typename TMeshIO::Pointer fsMeshIO,
7373
ITK_TEST_EXPECT_EQUAL(numberOfCells, fsMeshIO->GetNumberOfCells());
7474
ITK_TEST_EXPECT_EQUAL(numberOfCellPixels, fsMeshIO->GetNumberOfCellPixels());
7575

76-
// Use sufficiently large buffer sizes
77-
itk::SizeValueType pointBufferSize = 2000;
78-
itk::SizeValueType pointDataBufferSize = 2000;
79-
80-
itk::SizeValueType cellBufferSize = 2000;
76+
itk::SizeValueType pointBufferSize = 3 * sizeof(float) * fsMeshIO->GetNumberOfPoints();
77+
itk::SizeValueType cellBufferSize = 3 * sizeof(uint32_t) * fsMeshIO->GetNumberOfCells();
8178

8279
const std::shared_ptr<void> pointBuffer =
8380
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetPointComponentType(), pointBufferSize);
84-
const std::shared_ptr<void> pointDataBuffer =
85-
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
8681
const std::shared_ptr<void> cellBuffer =
8782
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetCellComponentType(), cellBufferSize);
8883

8984
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPoints(pointBuffer.get()));
90-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPointData(pointDataBuffer.get()));
91-
9285
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadCells(cellBuffer.get()));
9386

94-
void * cellDataBuffer = nullptr;
9587
// Not used; empty method body; called for coverage purposes
96-
fsMeshIO->ReadCellData(cellDataBuffer);
88+
fsMeshIO->ReadCellData(nullptr);
9789

9890
// Test writing exceptions
9991
fsMeshIO->SetFileName("");
92+
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteMeshInformation());
10093
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePoints(pointBuffer.get()));
101-
if (dynamic_cast<itk::FreeSurferBinaryMeshIO *>(fsMeshIO.GetPointer()))
102-
{
103-
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer.get()));
104-
}
105-
10694
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteCells(cellBuffer.get()));
107-
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteMeshInformation());
10895

10996
ITK_TEST_EXPECT_TRUE(!fsMeshIO->CanWriteFile(notAFsOutputFileName));
11097

11198
ITK_TEST_EXPECT_TRUE(fsMeshIO->CanWriteFile(outputFileName));
11299
fsMeshIO->SetFileName(outputFileName);
113100

114101
// Write the actual data
102+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WriteMeshInformation());
115103
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePoints(pointBuffer.get()));
116-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer.get()));
117-
118104
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WriteCells(cellBuffer.get()));
119105

120106
// Not used; empty method body; called for coverage purposes
121-
fsMeshIO->WriteCellData(cellDataBuffer);
122-
123-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WriteMeshInformation());
107+
fsMeshIO->WriteCellData(nullptr);
124108

125109
// Not used; empty method body; called for coverage purposes
126110
fsMeshIO->Write();
127111

128-
129112
// Read back the written image and check the properties
130113
readWritefsMeshIO->SetFileName(outputFileName);
131114
readWritefsMeshIO->ReadMeshInformation();

0 commit comments

Comments
 (0)