From e73cf6292c8109621e18d8a89c019976150d9949 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Wed, 17 Jul 2019 14:44:00 +0200
Subject: [PATCH] Attempt to fix coverity errors.

---
 DDCore/src/DetectorImp.cpp           | 6 +++---
 DDCore/src/plugins/CodeGenerator.cpp | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp
index 75851c045..a27da8b3b 100644
--- a/DDCore/src/DetectorImp.cpp
+++ b/DDCore/src/DetectorImp.cpp
@@ -77,11 +77,11 @@ namespace {
     ~Instances() = default;
     Detector* get(const string& name)   {
       auto i = detectors.find(name);
-      return i==detectors.end() ? 0 : (*i).second;
+      return i == detectors.end() ? 0 : (*i).second;
     }
     void insert(const string& name, Detector* detector)   {
       auto i = detectors.find(name);
-      if ( i==detectors.end() )   {
+      if ( i == detectors.end() )   {
         detectors.emplace(name,detector);
         return;
       }
@@ -89,7 +89,7 @@ namespace {
     }
     Detector* remove(const string& name)   {
       auto i = detectors.find(name);
-      if ( i==detectors.end() )  {
+      if ( i != detectors.end() )  {
         Detector* det = (*i).second;
         detectors.erase(i);
         return det;
diff --git a/DDCore/src/plugins/CodeGenerator.cpp b/DDCore/src/plugins/CodeGenerator.cpp
index 456fdaa68..2143587c8 100644
--- a/DDCore/src/plugins/CodeGenerator.cpp
+++ b/DDCore/src/plugins/CodeGenerator.cpp
@@ -406,14 +406,12 @@ namespace {
   
   ostream& Actor::handleMatrix(ostream& log, TGeoMatrix* mat)   {
     if ( mat && matrices.find(mat) == matrices.end() )  {
-      const Double_t*	rot = mat->GetRotationMatrix();
-      const Double_t*	tra = mat->GetTranslation();
-      const Double_t*	sca = mat->GetScale();
       string name = obj_name("matrix",mat);
       log << "{" << newline
           << "\t TGeoHMatrix* mat = new TGeoHMatrix(\"" << mat->GetName() << "\");" << newline
           << "\t matrices[" << pointer(mat) << "] = mat;" << newline;
       if ( mat->IsTranslation() )   {
+        const Double_t*	tra = mat->GetTranslation();
         log << "\t Double_t trans[] = {";
         for(size_t i=0; tra && i<3; ++i)  {
           log << tra[i];
@@ -422,7 +420,8 @@ namespace {
         log << newline << "\t mat->SetTranslation(trans);" << newline;
       }
       if ( mat->IsRotation() )   {
-        if ( rot[0] != 1e0 || rot[4] != 1e0 || rot[8] != 1e0)  {
+        const Double_t*	rot = mat->GetRotationMatrix();
+        if ( rot && (rot[0] != 1e0 || rot[4] != 1e0 || rot[8] != 1e0) )  {
           log << "\t Double_t rot[] = {";
           for(size_t i=0; rot && i<9; ++i)  {
             log << rot[i];
@@ -432,6 +431,7 @@ namespace {
         }
       }
       if ( mat->IsScale() )   {
+        const Double_t*	sca = mat->GetScale();
         log << "\t Double_t scale[] = {";
         for(size_t i=0; sca && i<3; ++i)  {
           log << sca[i];
-- 
GitLab