From e09ab0259544a006d4dfbe7bf6f7798c5718fa67 Mon Sep 17 00:00:00 2001
From: Atlas DQM <atlasdqm@cern.ch>
Date: Tue, 28 Jul 2020 22:38:53 +0200
Subject: [PATCH] Protect against invalid data when PNG not requested

---
 .../DataQualityUtils/DataQualityUtils/HanOutputFile.h  |  2 ++
 DataQuality/DataQualityUtils/src/HanOutputFile.cxx     | 10 ++--------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h b/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h
index b952560ce64..9a497a51d5c 100644
--- a/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h
+++ b/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h
@@ -73,6 +73,8 @@ public:
   /**
    * cnvsType: 1=pngOnly;2=jsonOnly;3=pngAndJson
    */
+  const static int GENERATE_PNG        = 1; // Make PNG with TImage
+  const static int GENERATE_JSON       = 2; // Make JSON
   virtual int  saveAllHistograms( std::string location, bool drawRefs, std::string run_min_LB,int cnvsType = 1);
   static bool containsDir(std::string dirname, std::string maindir);
 
diff --git a/DataQuality/DataQualityUtils/src/HanOutputFile.cxx b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx
index f0b1565d1db..a6a57a1bdae 100644
--- a/DataQuality/DataQualityUtils/src/HanOutputFile.cxx
+++ b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx
@@ -1524,7 +1524,8 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam
   }
 
 
-  std::string rv(x, y);
+  std::string rv;
+  if (cnvsType & GENERATE_PNG) { rv.assign(x, y); };
   std::pair<std::string,std::string>rvPair{rv,json};
 
   delete img;
@@ -2773,8 +2774,6 @@ writeToFile(std::string fname ,std::string content)
 void HanOutputFile::
 convertToGraphics(int cnvsType, TCanvas* myC,std::string &json, TImage *img,char **x, int *y)
 {
-    int GENERATE_PNG        = 1; // Make PNG with TImage
-    int GENERATE_JSON       = 2; // Make JSON
     if (cnvsType & GENERATE_PNG) 
     {
         if(img) getImageBuffer(img,myC,x,y);
@@ -2788,8 +2787,6 @@ convertToGraphics(int cnvsType, TCanvas* myC,std::string &json, TImage *img,char
 void HanOutputFile::
 convertToGraphics(int cnvsType, TCanvas* myC,std::string namePNG,std::string nameJSON)
 {
-    int GENERATE_PNG        = 1; // Make PNG with TImage
-    int GENERATE_JSON       = 2; // Make JSON
     if (cnvsType & GENERATE_PNG) 
     {
         myC->SaveAs(namePNG.c_str());
@@ -2804,9 +2801,6 @@ convertToGraphics(int cnvsType, TCanvas* myC,std::string namePNG,std::string nam
 bool HanOutputFile::
 saveFile(int cnvsType, std::string pngfName,std::string pngContent, std::string jsonfName, std::string jsonfContent)
 {
-    int GENERATE_PNG        = 1; // Make PNG with TImage
-    int GENERATE_JSON       = 2; // Make JSON
-
     bool png =false;
     bool json=false;
     if (cnvsType & GENERATE_PNG) 
-- 
GitLab