From 03d97b23ecef772520b64632bdbd0ec85eec1f85 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 May 2017 20:15:30 +0200 Subject: [PATCH] Coverity: fix finding in COBLoader. --- code/COBLoader.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/code/COBLoader.cpp b/code/COBLoader.cpp index b5d4f890c..a92e231a5 100644 --- a/code/COBLoader.cpp +++ b/code/COBLoader.cpp @@ -941,20 +941,22 @@ void COBImporter::UnsupportedChunk_Binary( StreamReaderLE& reader, const ChunkIn // ------------------------------------------------------------------------------------------------ // tiny utility guard to aid me at staying within chunk boundaries. class chunk_guard { - public: - chunk_guard(const COB::ChunkInfo& nfo, StreamReaderLE& reader) - : nfo(nfo) - , reader(reader) - , cur(reader.GetCurrentPos()) - { + : nfo(nfo) + , reader(reader) + , cur(reader.GetCurrentPos()) { } ~chunk_guard() { // don't do anything if the size is not given if(nfo.size != static_cast(-1)) { - reader.IncPtr(static_cast(nfo.size)-reader.GetCurrentPos()+cur); + try { + reader.IncPtr( static_cast< int >( nfo.size ) - reader.GetCurrentPos() + cur ); + } catch ( DeadlyImportError e ) { + // out of limit so correct the value + reader.IncPtr( reader.GetReadLimit() ); + } } }