From 7f2c51c8df7cf2fc59681e9b4cad0d9b26506570 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Tue, 4 Dec 2018 16:40:03 -0600 Subject: [PATCH] Do not hold on to empty strings passed to getByLabel When using PyROOT, the string addresses passed to getByLabel are temporary so we can not hold onto the address even for empty strings. --- DataFormats/FWLite/src/DataGetterHelper.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/DataFormats/FWLite/src/DataGetterHelper.cc b/DataFormats/FWLite/src/DataGetterHelper.cc index d0de585bdd6e6..8148da39bdb23 100644 --- a/DataFormats/FWLite/src/DataGetterHelper.cc +++ b/DataFormats/FWLite/src/DataGetterHelper.cc @@ -44,6 +44,7 @@ namespace fwlite { // // empty object used to signal that the branch requested was not found static internal::Data branchNotFound; + static char kEmptyString[1] = {0}; // // constructors and destructor @@ -218,16 +219,16 @@ namespace fwlite { std::strncpy(newModule,iModuleLabel,moduleLabelLen); labels_.push_back(newModule); - char* newProduct = const_cast(key.product()); - if(newProduct[0] != 0) { - size_t newProductLen = strlen(newProduct)+1; + char* newProduct = kEmptyString; + if(key.product()[0] != 0) { + size_t newProductLen = strlen(key.product())+1; newProduct = new char[newProductLen]; std::strncpy(newProduct,key.product(),newProductLen); labels_.push_back(newProduct); } - char* newProcess = const_cast(key.process()); - if(newProcess[0]!=0) { - size_t newProcessLen = strlen(newProcess)+1; + char* newProcess = kEmptyString; + if(key.process()[0]!=0) { + size_t newProcessLen = strlen(key.process())+1; newProcess = new char[newProcessLen]; std::strncpy(newProcess,key.process(),newProcessLen); labels_.push_back(newProcess);