]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Safely cast FFBEffect& to FFBPeriodicEffect& in operator==
authorMichal Malý <madcatxster@prifuk.cz>
Wed, 4 Dec 2013 16:53:15 +0000 (17:53 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Wed, 4 Dec 2013 16:53:15 +0000 (17:53 +0100)
ffbperiodiceffect.cpp

index 2099debf83431ff4b4e53c3651035476a3deaa60..62898dfdbb9452e859cab9ff5452e4a64e7592bc 100644 (file)
@@ -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<const FFBPeriodicEffect&>(other).m_params->waveform;
+  else {
+    try {
+      const FFBPeriodicEffect& eff = dynamic_cast<const FFBPeriodicEffect&>(other);
+      return this->m_params->waveform == eff.m_params->waveform;
+    } catch(std::bad_cast&) {
+      return false;
+    }
+  }
 }
 
 bool FFBPeriodicEffect::operator!=(const FFBEffect& other) const