misc: Use safe_cast when assumptions are made about return value
authorAndreas Hansson <andreas.hansson@arm.com>
Fri, 19 Sep 2014 14:35:11 +0000 (10:35 -0400)
committerAndreas Hansson <andreas.hansson@arm.com>
Fri, 19 Sep 2014 14:35:11 +0000 (10:35 -0400)
This patch changes two dynamic_cast to safe_cast as we assume the
return value is not NULL (without checking).

src/cpu/testers/memtest/memtest.cc
src/mem/packet.cc

index 6dc2ccb73fce5120555f413bb6dd4060bfbcc213..d949178c269be4a5bbfeb2b68e725e3db819e493 100644 (file)
@@ -170,7 +170,7 @@ MemTest::completeRequest(PacketPtr pkt)
             pkt->isError() ? "error" : "success");
 
     MemTestSenderState *state =
-        dynamic_cast<MemTestSenderState *>(pkt->senderState);
+        safe_cast<MemTestSenderState *>(pkt->senderState);
 
     uint8_t *data = state->data;
     uint8_t *pkt_data = pkt->getPtr<uint8_t>();
index 5b08342858f250f6aa953f2677e3f681c4aab01c..8bbd7ff18e1bd3452c3138a064c6b4bef7985160 100644 (file)
@@ -189,7 +189,7 @@ Packet::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
 
     // check print first since it doesn't require data
     if (isPrint()) {
-        dynamic_cast<PrintReqState*>(senderState)->printObj(obj);
+        safe_cast<PrintReqState*>(senderState)->printObj(obj);
         return false;
     }