Skip to content
Snippets Groups Projects
Commit 7194312e authored by Julien Michel's avatar Julien Michel
Browse files

COV: Fixing coverity issues (unchecked dynamic cast)

parent a8d07dfb
No related branches found
No related tags found
No related merge requests found
......@@ -318,6 +318,15 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
typename GDALImageIO::Pointer imageIO = dynamic_cast<GDALImageIO*>(this->GetImageIO());
if(imageIO.IsNull())
{
otb::ImageFileReaderException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " ImageIO is of kind GDALImageIO, but fails to dynamic_cast (this should never happen)."<< std::endl;
e.SetDescription(msg.str().c_str());
throw e;
}
// Hint the IO whether the OTB image type takes complex pixels
// this will determine the strategy to fill up a vector image
OutputImagePixelType dummy;
......@@ -728,8 +737,12 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
if (strcmp(this->m_ImageIO->GetNameOfClass(), "GDALImageIO") == 0)
{
typename GDALImageIO::Pointer imageIO = dynamic_cast<GDALImageIO*>(this->GetImageIO());
imageIO->GetResolutionInfo(res,desc);
return true;
if(imageIO.IsNotNull())
{
imageIO->GetResolutionInfo(res,desc);
return true;
}
}
#if defined(OTB_USE_JPEG2000)
......@@ -737,8 +750,12 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
if (strcmp(this->m_ImageIO->GetNameOfClass(), "JPEG2000ImageIO") == 0)
{
typename JPEG2000ImageIO::Pointer imageIO = dynamic_cast<JPEG2000ImageIO*>(this->GetImageIO());
imageIO->GetResolutionInfo(res,desc);
return true;
if(imageIO.IsNotNull())
{
imageIO->GetResolutionInfo(res,desc);
return true;
}
}
#endif
......
......@@ -452,7 +452,8 @@ ImageFileWriter<TInputImage>
i != allobjects.end(); ++i)
{
otb::ImageIOBase* io = dynamic_cast<otb::ImageIOBase*>(i->GetPointer());
msg << " " << io->GetNameOfClass() << std::endl;
if(io)
msg << " " << io->GetNameOfClass() << std::endl;
}
msg << " You probably failed to set a file suffix, or" << std::endl;
msg << " set the suffix to an unsupported type." << std::endl;
......@@ -466,6 +467,16 @@ ImageFileWriter<TInputImage>
&& m_FilenameHelper->gdalCreationOptionsIsSet() )
{
typename GDALImageIO::Pointer imageIO = dynamic_cast<GDALImageIO*>(m_ImageIO.GetPointer());
if(imageIO.IsNull())
{
otb::ImageFileWriterException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " ImageIO is of kind GDALImageIO, but fails to dynamic_cast (this should never happen)."<< std::endl;
e.SetDescription(msg.str().c_str());
throw e;
}
imageIO->SetOptions(m_FilenameHelper->GetgdalCreationOptions());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment