From d34ddec2ea804d8782ee081de712f824a7b14089 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 25 May 2016 14:54:59 +0100 Subject: [PATCH] Use localtime_r instead of localtime. Fixes lockup --- demuxer.cc | 0 log.cc | 9 ++++----- media.cc | 13 ++++++------- vepg.cc | 40 +++++++++++++++++++-------------------- vepglistadvanced.cc | 26 ++++++++++++------------- vepgsettimer.cc | 26 ++++++++++++------------- vradiorec.cc | 5 +++-- vrecordinglistadvanced.cc | 14 +++++++------- vrecordinglistclassic.cc | 8 ++++---- vtimeredit.cc | 10 +++++----- vtimerlist.cc | 13 +++++++------ vvideolivetv.cc | 13 +++++++------ vvideomedia.cc | 5 +++-- vvideorec.cc | 5 +++-- vwelcome.cc | 5 +++-- 15 files changed, 98 insertions(+), 94 deletions(-) mode change 100755 => 100644 demuxer.cc diff --git a/demuxer.cc b/demuxer.cc old mode 100755 new mode 100644 diff --git a/log.cc b/log.cc index 1d8c575..a532d5a 100644 --- a/log.cc +++ b/log.cc @@ -107,16 +107,15 @@ int Log::log(const char *fromModule, int level,const char* message, ...) #ifndef _MSC_VER struct timeval tv; gettimeofday(&tv, NULL); - struct tm* tms = localtime(&tv.tv_sec); + struct tm tms; + localtime_r(&tv.tv_sec, &tms); + spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", &tms); + spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec); #else struct _timeb tb; _ftime(&tb); struct tm* tms = localtime(&tb.time); -#endif spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tms); -#ifndef _MSC_VER - spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec); -#else spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tb.millitm); #endif diff --git a/media.cc b/media.cc index f376614..3901049 100644 --- a/media.cc +++ b/media.cc @@ -230,16 +230,15 @@ bool Media::hasDisplayName() const { char * Media::getTimeString(char * buffer) const { if (! buffer) buffer=new char[TIMEBUFLEN]; - struct tm ltime; time_t tTime = (time_t)getTime(); - struct tm *btime = localtime(&tTime); - memcpy(<ime,btime, sizeof(struct tm)); - btime=<ime; - if (btime && tTime != 0) { + struct tm btime; + localtime_r(&tTime, &btime); + + if (tTime != 0) { #ifndef _MSC_VER - strftime(buffer,TIMEBUFLEN, "%0g/%0m/%0d %0H:%0M ", btime); + strftime(buffer,TIMEBUFLEN, "%0g/%0m/%0d %0H:%0M ", &btime); #else - strftime(buffer,TIMEBUFLEN, "%Y/%m/%d %H:%M ", btime); + strftime(buffer,TIMEBUFLEN, "%Y/%m/%d %H:%M ", &btime); #endif } diff --git a/vepg.cc b/vepg.cc index 94624f6..a5babd0 100644 --- a/vepg.cc +++ b/vepg.cc @@ -215,24 +215,24 @@ VEpg* VEpg::getInstance() void VEpg::setInfo(Event* event) { time_t t; - struct tm* btime; // to hold programme start and end time + struct tm btime; // to hold programme start and end time char timeString[9]; // to hold programme start and end time int length = strlen(event->title); // calculate length of programme title string char* title = new char[length + 15]; // create string to hold start time, end time and programme title time_t eventtime = event->time; - btime = localtime((time_t*)&eventtime); //get programme start time + localtime_r((time_t*)&eventtime, &btime); //get programme start time #ifndef _MSC_VER - strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm - + strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm - #else - strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm - + strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm - #endif strcpy(title, timeString); // put it in our buffer t = event->time + event->duration; //get programme end time - btime = localtime(&t); + localtime_r(&t, &btime); #ifndef _MSC_VER - strftime(timeString, 7, "%0H:%0M ", btime); // and format it as hh:mm - + strftime(timeString, 7, "%0H:%0M ", &btime); // and format it as hh:mm - #else - strftime(timeString, 7, "%H:%M ", btime); // and format it as hh:mm - + strftime(timeString, 7, "%H:%M ", &btime); // and format it as hh:mm - #endif strcat(title, timeString); // put it in our buffer @@ -540,24 +540,24 @@ void VEpg::drawgrid() // redraws grid and select programme t = ltime; - struct tm* tms; - tms = localtime(&t); - strftime(timeString, 19, "%a %d %b", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%a %d %b", &tms); int timey = chanListbox.getRootBoxOffsetY() - getFontHeight() - 3; int timex = 135; drawTextRJ(timeString, timex - 10, timey, DrawStyle::LIGHTTEXT); // print date - strftime(timeString, 19, "%H:%M", tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, timex, timey, DrawStyle::LIGHTTEXT); // print left time rectangle(155, timey + getFontHeight(), 2, 7, white); t = t + 3600; - tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, timex + 180, timey, DrawStyle::LIGHTTEXT); // print middle time rectangle(335, timey + getFontHeight(), 2, 7, white); t = t + 3600; - tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, timex + 360, timey, DrawStyle::LIGHTTEXT); // print right time rectangle(515, timey + getFontHeight(), 2, 7, white); // pointer to selTime @@ -759,11 +759,11 @@ void VEpg::paintCell(Event* event, int yOffset, const DrawStyle& bg, const DrawS time_t VEpg::prevHour(time_t* t) { - struct tm* tms; - tms = localtime(t); - tms->tm_sec = 0; - tms->tm_min = 0; - return mktime(tms); + struct tm tms; + localtime_r(t, &tms); + tms.tm_sec = 0; + tms.tm_min = 0; + return mktime(&tms); } void VEpg::processMessage(Message* m) diff --git a/vepglistadvanced.cc b/vepglistadvanced.cc index 0ac6b92..7a02a8d 100644 --- a/vepglistadvanced.cc +++ b/vepglistadvanced.cc @@ -454,7 +454,7 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop) char tempA[300]; // FIXME this is guesswork! char tempB[300]; // FIXME char tempC[300]; // FIXME - struct tm* btime; + struct tm btime; @@ -469,10 +469,10 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop) time_t eventStartTime = (time_t)currentEvent->time; time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration); - btime = localtime(&eventStartTime); - strftime(tempA, 299, "%d/%m/%y %H:%M ", btime); - btime = localtime(&eventEndTime); - strftime(tempB, 299, "- %H:%M ", btime); + localtime_r(&eventStartTime, &btime); + strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); + localtime_r(&eventEndTime, &btime); + strftime(tempB, 299, "- %H:%M ", &btime); //#endif sprintf(tempC, "\t %s\n \t \t%s%s", currentEvent->title,tempA,tempB); // New TVMedia stuff @@ -511,7 +511,7 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) char tempA[300]; // FIXME this is guesswork! char tempB[300]; // FIXME char tempC[300]; // FIXME - struct tm* btime; + struct tm btime; @@ -536,10 +536,10 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) time_t eventStartTime = (time_t)currentEvent->time; time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration); - btime = localtime(&eventStartTime); - strftime(tempA, 299, "%H:%M ", btime); - btime = localtime(&eventEndTime); - strftime(tempB, 299, "- %H:%M ", btime); + localtime_r(&eventStartTime, &btime); + strftime(tempA, 299, "%H:%M ", &btime); + localtime_r(&eventEndTime, &btime); + strftime(tempB, 299, "- %H:%M ", &btime); //#endif sprintf(tempC, "%s\n%s\t %s%s", currentEvent->title, chan->name,tempA,tempB); @@ -610,11 +610,11 @@ void VEpgListAdvanced::draw(bool doIndexPop) char freeSpace[50]; - struct tm* btime; + struct tm btime; time_t now; time(&now); - btime = localtime(&now); - strftime(freeSpace, 299, "%d/%m/%y", btime); + localtime_r(&now, &btime); + strftime(freeSpace, 299, "%d/%m/%y", &btime); drawTextRJ(freeSpace, getWidth(), 5, DrawStyle::LIGHTTEXT); diff --git a/vepgsettimer.cc b/vepgsettimer.cc index 582ce68..3f7ad7b 100644 --- a/vepgsettimer.cc +++ b/vepgsettimer.cc @@ -84,7 +84,7 @@ char* VEpgSetTimer::genTimerString() char* timerString = new char[1024]; // Other - struct tm* btime; + struct tm btime; int flags; char dateString[20]; char startMargin[10]; @@ -108,9 +108,9 @@ char* VEpgSetTimer::genTimerString() else strcpy(startMargin, "5"); startTime = event->time - (atoi(startMargin) * 60); - btime = localtime(&startTime); - strftime(dateString, 19, "%Y-%m-%d", btime); - strftime(startString, 9, "%H%M", btime); + localtime_r(&startTime, &btime); + strftime(dateString, 19, "%Y-%m-%d", &btime); + strftime(startString, 9, "%H%M", &btime); char* endMarginConfig = vdr->configLoad("Timers", "End margin"); if (endMarginConfig) @@ -121,8 +121,8 @@ char* VEpgSetTimer::genTimerString() else strcpy(endMargin, "5"); endTime = event->time + event->duration + (atoi(endMargin) * 60); - btime = localtime(&endTime); - strftime(endString, 9, "%H%M", btime); + localtime_r(&endTime, &btime); + strftime(endString, 9, "%H%M", &btime); char* priorityConfig = vdr->configLoad("Timers", "Priority"); if (priorityConfig) @@ -178,22 +178,22 @@ void VEpgSetTimer::draw() char fullString[20]; time_t t; - struct tm* btime; + struct tm btime; char timeString[10]; time_t eventtime = event->time; - btime = localtime(&eventtime); + localtime_r(&eventtime, &btime); #ifndef _MSC_VER - strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm - + strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm - #else - strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm - + strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm - #endif strcpy(fullString, timeString); // put it in our buffer t = event->time + event->duration; //get programme end time - btime = localtime(&t); + localtime_r(&t, &btime); #ifndef _MSC_VER - strftime(timeString, 9, "%0H:%0M", btime); // and format it as hh:mm - + strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm - #else - strftime(timeString, 9, "%H:%M", btime); // and format it as hh:mm - + strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm - #endif strcat(fullString, timeString); // put it in our buffer diff --git a/vradiorec.cc b/vradiorec.cc index 04f2cc3..b48eec1 100644 --- a/vradiorec.cc +++ b/vradiorec.cc @@ -429,8 +429,9 @@ void VRadioRec::drawBarClocks() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); // Draw clocks diff --git a/vrecordinglistadvanced.cc b/vrecordinglistadvanced.cc index b4fbb9c..bed9504 100644 --- a/vrecordinglistadvanced.cc +++ b/vrecordinglistadvanced.cc @@ -96,7 +96,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) char tempA[300]; // FIXME this is guesswork! char tempB[300]; // FIXME - struct tm* btime; + struct tm btime; Directory* currentSubDir; DirectoryList::iterator i; @@ -127,12 +127,12 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) { currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - btime = localtime(&recStartTime); + localtime_r(&recStartTime, &btime); //NMT does not like this too! //#ifndef _MSC_VER -// strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime); +// strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); //#else - strftime(tempA, 299, "%d/%m/%y %H:%M ", btime); + strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); //#endif sprintf(tempB, "%c\t%s\n \t%s", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(),tempA); // New TVMedia stuff @@ -281,14 +281,14 @@ void VRecordingListAdvanced::updateSelection() RecordingList::iterator j; RecordingList & recList = toShowDir->recList; char tempA[300]; - struct tm* btime; + struct tm btime; for (j = recList.begin(); j != recList.end(); j++) { currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - btime = localtime(&recStartTime); - strftime(tempA, 299, "%d/%m/%y %H:%M ", btime); + localtime_r(&recStartTime, &btime); + strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n"; diff --git a/vrecordinglistclassic.cc b/vrecordinglistclassic.cc index 1322e53..82ffbb4 100644 --- a/vrecordinglistclassic.cc +++ b/vrecordinglistclassic.cc @@ -76,7 +76,7 @@ void VRecordingListClassic::drawData(bool doIndexPop) char tempA[300]; // FIXME this is guesswork! char tempB[300]; // FIXME - struct tm* btime; + struct tm btime; Directory* currentSubDir; DirectoryList::iterator i; @@ -97,12 +97,12 @@ void VRecordingListClassic::drawData(bool doIndexPop) { currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - btime = localtime(&recStartTime); + localtime_r(&recStartTime, &btime); //NMT does not like this too! //#ifndef _MSC_VER -// strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime); +// strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); //#else - strftime(tempA, 299, "%d/%m %H:%M ", btime); + strftime(tempA, 299, "%d/%m %H:%M ", &btime); //#endif sprintf(tempB, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName()); diff --git a/vtimeredit.cc b/vtimeredit.cc index 313f8cc..0e8795d 100644 --- a/vtimeredit.cc +++ b/vtimeredit.cc @@ -95,7 +95,7 @@ void VTimerEdit::draw() // Temp char buffer[1000]; - struct tm* tms; + struct tm tms; xpos = 150; ypos = 50; @@ -120,14 +120,14 @@ void VTimerEdit::draw() // Start time_t rectime = recTimer->startTime; - tms = localtime((time_t*)&rectime); - strftime(buffer, 999, "%d/%m %H:%M", tms); + localtime_r((time_t*)&rectime, &tms); + strftime(buffer, 999, "%d/%m %H:%M", &tms); drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT); ypos += fontheight; // Stop rectime = recTimer->startTime; - tms = localtime((time_t*)&rectime); - strftime(buffer, 999, "%d/%m %H:%M", tms); + localtime_r((time_t*)&rectime, &tms); + strftime(buffer, 999, "%d/%m %H:%M", &tms); drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT); ypos += fontheight; // Priority diff --git a/vtimerlist.cc b/vtimerlist.cc index 2ecaf3f..29d5027 100644 --- a/vtimerlist.cc +++ b/vtimerlist.cc @@ -137,7 +137,7 @@ bool VTimerList::load() char strA[300]; char strB[300]; - struct tm* btime; + struct tm btime; // FIXME all drawing stuff in this class and sl.clear somewhere?! @@ -150,9 +150,9 @@ bool VTimerList::load() for (UINT i = 0; i < recTimerList->size(); i++) { recTimer = (*recTimerList)[i]; - time_t rectime = recTimer->startTime; - btime = localtime((time_t*)&rectime); - strftime(strA, 299, "%d/%m %H:%M ", btime); + time_t rectime = recTimer->startTime; + localtime_r((time_t*)&rectime, &btime); + strftime(strA, 299, "%d/%m %H:%M ", &btime); SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName()); sl.addOption(strB, (ULONG)recTimer, first); first = 0; @@ -171,8 +171,9 @@ void VTimerList::drawClock() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%d/%m %H:%M:%S", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%d/%m %H:%M:%S", &tms); drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT); Timers::getInstance()->setTimerT(this, 1, t + 1); diff --git a/vvideolivetv.cc b/vvideolivetv.cc index d140d24..0901d0d 100644 --- a/vvideolivetv.cc +++ b/vvideolivetv.cc @@ -770,7 +770,7 @@ void VVideoLiveTV::setNowNextData() char tempString[300]; char tempString2[300]; - struct tm* btime; + struct tm btime; Event* event; int eventListSize = eventList->size(); std::stringstream string; @@ -779,11 +779,11 @@ void VVideoLiveTV::setNowNextData() event = (*eventList)[i]; time_t etime = event->time; - btime = localtime(&etime); + localtime_r(&etime, &btime); #ifndef _MSC_VER - strftime(tempString2, 299, "%0H:%0M ", btime); + strftime(tempString2, 299, "%0H:%0M ", &btime); #else - strftime(tempString2, 299, "%H:%M ", btime); + strftime(tempString2, 299, "%H:%M ", &btime); #endif SNPRINTF(tempString, 299, "%s %s", tempString2, event->title); string << tempString << "\n"; @@ -860,8 +860,9 @@ void VVideoLiveTV::setClock() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); clock.setText(timeString); time_t dt = 60 - (t % 60); // seconds to the next minute diff --git a/vvideomedia.cc b/vvideomedia.cc index 6f97b59..02a1485 100644 --- a/vvideomedia.cc +++ b/vvideomedia.cc @@ -615,8 +615,9 @@ void VVideoMedia::drawBarClocks() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); ULLONG lenPTS=player->getLenPTS(); diff --git a/vvideorec.cc b/vvideorec.cc index 8fca589..7156053 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -963,8 +963,9 @@ void VVideoRec::drawBarClocks() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); // Draw clocks diff --git a/vwelcome.cc b/vwelcome.cc index 733a47d..b92ad5d 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -160,8 +160,9 @@ void VWelcome::drawClock() char timeString[20]; time_t t; time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); + struct tm tms; + localtime_r(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT); time_t dt = 60 - (t % 60); // seconds to the next minute -- 2.39.2