From 2fe7bc857caab5aa249b6a54fdadc9579de4cf02 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Tue, 3 Feb 2015 11:12:21 +0100 Subject: [PATCH] COV: Fixing coverity issues (unchecked dynamic cast) --- Code/IO/otbKMLVectorDataIO.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Code/IO/otbKMLVectorDataIO.cxx b/Code/IO/otbKMLVectorDataIO.cxx index 74c3f4847e..cd86b53aad 100644 --- a/Code/IO/otbKMLVectorDataIO.cxx +++ b/Code/IO/otbKMLVectorDataIO.cxx @@ -454,6 +454,12 @@ KMLVectorDataIO ::Read(itk::DataObject* datag) { VectorDataPointerType data = dynamic_cast<VectorDataType*>(datag); + + if(!data) + { + itkExceptionMacro(<< "Dynamic cast error: data to write is not of type otb::VectorData (this should never happen)."); + } + std::string kml; bool status = kmlbase::File::ReadFileToString(this->m_FileName, &kml); if (status == false) @@ -519,8 +525,14 @@ void KMLVectorDataIO::Write(const itk::DataObject* datag, char ** itkNotUsed(pap // Retrieve data required for georeferencing VectorDataConstPointerType data_in = dynamic_cast<const VectorDataType*>(datag); + VectorDataConstPointerType data = data_in; + if(!data) + { + itkExceptionMacro(<< "Dynamic cast error: data to write is not of type otb::VectorData (this should never happen)."); + } + std::string projectionRefWkt = data->GetProjectionRef(); OGRSpatialReferenceH oSRS = OSRNewSpatialReference(projectionRefWkt.c_str()); if (!OSRIsGeographic(oSRS)) -- GitLab