From: Michal MalĂ˝ Date: Wed, 4 Dec 2013 16:53:15 +0000 (+0100) Subject: Safely cast FFBEffect& to FFBPeriodicEffect& in operator== X-Git-Tag: 0.2d~6 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=d5df35c05dadad1575d1ea80b98412a057854d50;p=FFBChecker.git Safely cast FFBEffect& to FFBPeriodicEffect& in operator== --- diff --git a/ffbperiodiceffect.cpp b/ffbperiodiceffect.cpp index 2099deb..62898df 100644 --- a/ffbperiodiceffect.cpp +++ b/ffbperiodiceffect.cpp @@ -115,8 +115,14 @@ bool FFBPeriodicEffect::operator==(const FFBEffect& other) const { if (this->type() != other.type()) return false; - else - return this->m_params->waveform == dynamic_cast(other).m_params->waveform; + else { + try { + const FFBPeriodicEffect& eff = dynamic_cast(other); + return this->m_params->waveform == eff.m_params->waveform; + } catch(std::bad_cast&) { + return false; + } + } } bool FFBPeriodicEffect::operator!=(const FFBEffect& other) const