From 50a7ab3b0d19b7bc21a8d11ae5352cce20a1b306 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 3 Nov 2022 09:43:33 -0400 Subject: [PATCH] Avoid pointer cast to time_t from incompatible type (#427) Resolves #426 cherry-pick 235a2676 --- StRoot/StDaqLib/SC/SC_Reader.cxx | 5 +++-- StRoot/StDaqLib/SSD/SSD_Reader.cxx | 5 +++-- StRoot/StEEmcUtil/EEfeeRaw/RootWrapper.cxx | 4 +++- StRoot/St_trg_Maker/year2003.cxx | 4 ++-- StRoot/StarRoot/TUnixTime.cxx | 23 +++++++++++----------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/StRoot/StDaqLib/SC/SC_Reader.cxx b/StRoot/StDaqLib/SC/SC_Reader.cxx index 582fbaedeb4..055dafbd51b 100644 --- a/StRoot/StDaqLib/SC/SC_Reader.cxx +++ b/StRoot/StDaqLib/SC/SC_Reader.cxx @@ -9,6 +9,7 @@ #include #include +#include using namespace OLDEVP; @@ -97,8 +98,8 @@ SC_Reader::SC_Reader(EventReader *er) { //Keep BBCBkg scalers flipped as theyStRoot/StDaqLib/SC/SC_Reader.cxx were historically before 2009 //Note that new DAQ reader leads to UTime = 0, or tm_year=70 (1970) //but new DAQ reader only gets used for 2009+ anyhow - unsigned int UTime = er->getEventInfo().UnixTime; - struct tm *time=gmtime((time_t*) &UTime); + std::time_t utime = er->getEventInfo().UnixTime; + std::tm *time = gmtime(&utime); flipBBCBkg = (time->tm_year > 95 && time->tm_year < 109 ? 1 : 0) ; // LDate = (((1900+time->tm_year)*100 + 1 + time->tm_mon)*100 + time->tm_mday)*100; diff --git a/StRoot/StDaqLib/SSD/SSD_Reader.cxx b/StRoot/StDaqLib/SSD/SSD_Reader.cxx index 5e4bd5a3c88..2db2251b6b7 100644 --- a/StRoot/StDaqLib/SSD/SSD_Reader.cxx +++ b/StRoot/StDaqLib/SSD/SSD_Reader.cxx @@ -3,6 +3,7 @@ #include #include +#include static unsigned short log8to10_table[256] = { 0, 1, 2, 3, 4, 5, 6, 7, @@ -118,8 +119,8 @@ SSD_Reader::SSD_Reader(EventReader *er) { datap=er->getDATAP(); if (datap) { - unsigned int UTime = er->getEventInfo().UnixTime; - struct tm *time=gmtime((time_t*) &UTime); + std::time_t utime = er->getEventInfo().UnixTime; + std::tm *time = gmtime(&utime); //LDate = (((1900+time->tm_year)*100 + 1 + time->tm_mon)*100 + time->tm_mday)*100; //LDate = yyyymmdd diff --git a/StRoot/StEEmcUtil/EEfeeRaw/RootWrapper.cxx b/StRoot/StEEmcUtil/EEfeeRaw/RootWrapper.cxx index 718eecc6594..40185c99d8f 100644 --- a/StRoot/StEEmcUtil/EEfeeRaw/RootWrapper.cxx +++ b/StRoot/StEEmcUtil/EEfeeRaw/RootWrapper.cxx @@ -1,5 +1,6 @@ #include #include +#include #include "TROOT.h" #include "TFile.h" @@ -57,7 +58,8 @@ eemcfeerootopen_(long& run, long& runtime, char *chfile, int &nAuto, int len) char *idt = strchr(basefile,'.'); *idt = 0x00; // locate first dot } sprintf(filename,"%s/%s.ez.root",rootdir,basefile); - sprintf(comment,"run:%05ld, time:%s ",run,ctime((time_t *)&runtime)); + std::time_t utime = runtime; + sprintf(comment,"run:%05ld, time:%s ",run,ctime(&utime)); file = new TFile(filename,"RECREATE"); tree = new TTree("ezstar","A tree with FEE events"); diff --git a/StRoot/St_trg_Maker/year2003.cxx b/StRoot/St_trg_Maker/year2003.cxx index d80fb30a13d..f57df7ebaeb 100644 --- a/StRoot/St_trg_Maker/year2003.cxx +++ b/StRoot/St_trg_Maker/year2003.cxx @@ -101,8 +101,8 @@ void St_trg_Maker::Emc2003(St_dst_TrgDet *dst1) { //pp_dsm_to_patch[7] for after 01-Dec-2001, AA_dsm_to_patch[5] for before that date EventReader *er=fVictorPrelim->getEventReader(); EventInfo info=er->getEventInfo(); - unsigned int UnixTime=info.UnixTime; - struct tm *time=gmtime((time_t*) &UnixTime); + std::time_t utime = info.UnixTime; + std::tm *time = gmtime(&utime); int year=1900+time->tm_year; int month=1+time->tm_mon; int day=time->tm_mday; diff --git a/StRoot/StarRoot/TUnixTime.cxx b/StRoot/StarRoot/TUnixTime.cxx index 64b1e4c892a..395282dfa19 100644 --- a/StRoot/StarRoot/TUnixTime.cxx +++ b/StRoot/StarRoot/TUnixTime.cxx @@ -8,9 +8,9 @@ * *************************************************************************** **************************************************************************/ +#include #include #include -#include #include #include "TUnixTime.h" #include "TDatime.h" @@ -111,30 +111,29 @@ void TUnixTime::SetLTime(Int_t idate, Int_t itime) //______________________________________________________________________________ void TUnixTime::GetGTime(Int_t &idate, Int_t &itime) { - struct tm gt; - gt = *gmtime((time_t*)&fUTime); - tm2DateTime(idate,itime,>); + std::time_t utime = fUTime; + std::tm *gt = gmtime(&utime); + tm2DateTime(idate, itime, gt); } //______________________________________________________________________________ void TUnixTime::GetLTime(Int_t &idate, Int_t &itime) { - struct tm gt; - gt = *localtime((time_t*)&fUTime); - tm2DateTime(idate,itime,>); - + std::time_t utime = fUTime; + std::tm *gt = localtime(&utime); + tm2DateTime(idate, itime, gt); } //______________________________________________________________________________ TString TUnixTime::GetLString() { - TString ts(ctime((time_t*)&fUTime)); - return ts; + std::time_t utime = fUTime; + return TString(ctime(&utime)); } //______________________________________________________________________________ TString TUnixTime::GetGString() { - TString ts(asctime(gmtime((time_t*)&fUTime))); - return ts; + std::time_t utime = fUTime; + return TString(asctime(gmtime(&utime))); } //______________________________________________________________________________ void TUnixTime::SetLTime(const TDatime &loc)