Browse Source

[2887] use pointer based dynamic_cast instead of catching bad_cast

the effect is the same, but it should avoid unexpected result of
FreeBSD 9.1, which has binary incompatibility between libstdc++ and C++
compilers.  (and, avoiding try-catch would be better in terms of
performance anyway).
JINMEI Tatuya 12 years ago
parent
commit
22eb335a02
2 changed files with 8 additions and 9 deletions
  1. 4 6
      src/lib/datasrc/memory/rdataset.cc
  2. 4 3
      src/lib/dns/tsigrecord.cc

+ 4 - 6
src/lib/datasrc/memory/rdataset.cc

@@ -28,7 +28,6 @@
 #include <stdint.h>
 #include <algorithm>
 #include <cstring>
-#include <typeinfo>             // for bad_cast
 #include <new>                  // for the placement new
 
 using namespace isc::dns;
@@ -41,13 +40,12 @@ namespace memory {
 namespace {
 RRType
 getCoveredType(const Rdata& rdata) {
-    try {
-        const generic::RRSIG& rrsig_rdata =
-            dynamic_cast<const generic::RRSIG&>(rdata);
-        return (rrsig_rdata.typeCovered());
-    } catch (const std::bad_cast&) {
+    const generic::RRSIG* rrsig_rdata =
+        dynamic_cast<const generic::RRSIG*>(&rdata);
+    if (!rrsig_rdata) {
         isc_throw(BadValue, "Non RRSIG is given where it's expected");
     }
+    return (rrsig_rdata->typeCovered());
 }
 
 // A helper for lowestTTL: restore RRTTL object from wire-format 32-bit data.

+ 4 - 3
src/lib/dns/tsigrecord.cc

@@ -59,13 +59,14 @@ namespace {
 // of the constructor below.
 const any::TSIG&
 castToTSIGRdata(const rdata::Rdata& rdata) {
-    try {
-        return (dynamic_cast<const any::TSIG&>(rdata));
-    } catch (std::bad_cast&) {
+    const any::TSIG* tsig_rdata =
+        dynamic_cast<const any::TSIG*>(&rdata);
+    if (!tsig_rdata) {
         isc_throw(DNSMessageFORMERR,
                   "TSIG record is being constructed from "
                   "incompatible RDATA:" << rdata.toText());
     }
+    return (*tsig_rdata);
 }
 }