From f1a2c77305ffc72dc53d9114658089dd21c10237 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 19 Feb 2020 18:17:09 +0000 Subject: [PATCH] 20 CWFs, fix some snprintf calls --- defines.h | 2 + demuxerts.cc | 2 +- ledraspberry.cc | 2 +- playerliveradio.cc | 2 +- playerradio.cc | 4 +- vepg.cc | 2 +- vpicturebanner.cc | 2 +- vrecordinglist.h | 3 +- vrecordinglistadvanced.cc | 89 ++++++++++++++++++--------------------- vrecordinglistadvanced.h | 10 ++--- vrecordinglistclassic.cc | 29 ++++++------- vrecordinglistclassic.h | 11 ++--- vscreensaver.cc | 2 +- vtimerlist.cc | 28 ++++++------ vtimerlist.h | 20 +++------ 15 files changed, 94 insertions(+), 114 deletions(-) diff --git a/defines.h b/defines.h index 01b0f58..d6eed72 100644 --- a/defines.h +++ b/defines.h @@ -60,6 +60,8 @@ int getClockRealTime(struct timespec *tp); #define RemoteStartDev ""//No devices passed // FIXME - check C++ - I think some of these are in std:: now ? +// FIXME - Not on Windows. Obviously. Also _snprintf doesn't guarantee null termination. +// FIXME When the Windows code is upped to VS2015 use snprintf instead of _snprintf. #define SNPRINTF _snprintf #define VSNPRINTF _vsnprintf #define STRCASECMP _stricmp diff --git a/demuxerts.cc b/demuxerts.cc index f11ba51..26401f7 100644 --- a/demuxerts.cc +++ b/demuxerts.cc @@ -92,7 +92,7 @@ tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX); pinfo.hasaccessunit=false; } -int DemuxerTS::scan(UCHAR *buf, int len) +int DemuxerTS::scan(UCHAR* /*buf*/, int /*len*/) { switch (atype) { diff --git a/ledraspberry.cc b/ledraspberry.cc index 6269546..2b58e39 100644 --- a/ledraspberry.cc +++ b/ledraspberry.cc @@ -31,7 +31,7 @@ LedRaspberry::~LedRaspberry() { } -int LedRaspberry::init(int tdevice) +int LedRaspberry::init(int /*tdevice*/) { if (initted) return 0; FILE *led=fopen(GREEN_LED,"w"); diff --git a/playerliveradio.cc b/playerliveradio.cc index 54b9c29..585be83 100644 --- a/playerliveradio.cc +++ b/playerliveradio.cc @@ -153,7 +153,7 @@ void PlayerLiveRadio::stop() // ----------------------------------- Callback -void PlayerLiveRadio::call(void* caller) +void PlayerLiveRadio::call(void* /*caller*/) { } diff --git a/playerradio.cc b/playerradio.cc index cc184d2..93ac63d 100644 --- a/playerradio.cc +++ b/playerradio.cc @@ -334,6 +334,7 @@ void PlayerRadio::switchState(UCHAR toState, ULONG jumpToFrame) } } } + FALLTHROUGH // keep compiler happy (all posibilities return) case S_PAUSE_P: // from S_PAUSE_P ----------------------------------- { switch(toState) @@ -368,6 +369,7 @@ void PlayerRadio::switchState(UCHAR toState, ULONG jumpToFrame) } } } + FALLTHROUGH // keep compiler happy (all posibilities return) case S_STOP: // from S_STOP ----------------------------------- { switch(toState) @@ -462,7 +464,7 @@ void PlayerRadio::doConnectionLost() // ----------------------------------- Callback -void PlayerRadio::call(void* caller) +void PlayerRadio::call(void* /*caller*/) { threadSignalNoLock(); } diff --git a/vepg.cc b/vepg.cc index 7b29111..71609d0 100644 --- a/vepg.cc +++ b/vepg.cc @@ -346,7 +346,7 @@ void VEpg::drawData() Timers::getInstance()->setTimerT(this, 1, dt); } -void VEpg::timercall(int clientReference) +void VEpg::timercall(int /*clientReference*/) { drawData(); boxstack->update(this); diff --git a/vpicturebanner.cc b/vpicturebanner.cc index 76491a1..ad91656 100644 --- a/vpicturebanner.cc +++ b/vpicturebanner.cc @@ -88,7 +88,7 @@ void VPictureBanner::draw() } } -int VPictureBanner::handleCommand(int command) +int VPictureBanner::handleCommand(int /*command*/) { //don not handle commands - leave this to the picture viewer return 0; diff --git a/vrecordinglist.h b/vrecordinglist.h index 0a59671..7f49b27 100644 --- a/vrecordinglist.h +++ b/vrecordinglist.h @@ -42,8 +42,9 @@ class VRecordingList : public TBBoxx VRecordingList(); virtual ~VRecordingList(); - + using TBBoxx::draw; virtual void draw(bool doIndexPop = false)=0; + int handleCommand(int command); void processMessage(Message* m); bool load(); diff --git a/vrecordinglistadvanced.cc b/vrecordinglistadvanced.cc index b4e990b..9ed10d8 100644 --- a/vrecordinglistadvanced.cc +++ b/vrecordinglistadvanced.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2007 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,11 +14,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vrecordinglistadvanced.h" +#include +#include #include "recman.h" #include "directory.h" @@ -42,40 +42,39 @@ #include "seriesinfo.h" #include "staticartwork.h" -#include +#include "vrecordinglistadvanced.h" VRecordingListAdvanced::VRecordingListAdvanced() { - setSize(640, 500); //old setSize(570, 420); - createBuffer(); - - setPosition(40, 40); - - setTitleBarOn(1); - setTitleBarColour(DrawStyle::TITLEBARBACKGROUND); - TVMediaInfo *info= new TVMediaInfo(); - info->setStaticArtwork(sa_recordings); - setTitleBarIcon(info); - - sl.setPosition(10, 30 + 5); - sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30); - sl.setLinesPerOption(2.4f); - add(&sl); - - Region slarea=sl.getRegionR(); - - epg.setParaMode(true); - epg.setPosition(slarea.x +slarea.w+10 ,30+5); - epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30); - add(&epg); - epg.setText(""); - epg.setBackgroundColour(DrawStyle::VIEWBACKGROUND); - - epgTVmedia.setPosition(epg.getRegionR().w-100-10,10); - epgTVmedia.setSize(100,(UINT)(150/Osd::getInstance()->getPixelAspect())); - epg.add(&epgTVmedia); - + setSize(640, 500); + createBuffer(); + + setPosition(40, 40); + + setTitleBarOn(1); + setTitleBarColour(DrawStyle::TITLEBARBACKGROUND); + TVMediaInfo* info = new TVMediaInfo(); + info->setStaticArtwork(sa_recordings); + setTitleBarIcon(info); + + sl.setPosition(10, 30 + 5); + sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30); + sl.setLinesPerOption(2.4f); + add(&sl); + + Region slarea = sl.getRegionR(); + + epg.setParaMode(true); + epg.setPosition(slarea.x +slarea.w+10 ,30+5); + epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30); + add(&epg); + epg.setText(""); + epg.setBackgroundColour(DrawStyle::VIEWBACKGROUND); + + epgTVmedia.setPosition(epg.getRegionR().w-100-10,10); + epgTVmedia.setSize(100, static_cast(150/Osd::getInstance()->getPixelAspect())); + epg.add(&epgTVmedia); } VRecordingListAdvanced::~VRecordingListAdvanced() @@ -104,7 +103,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) for (i = dirList->begin(); i != dirList->end(); i++) { currentSubDir = *i; - SNPRINTF(tempA, 299, tr("\t%s \n \t %lu/%lu"), currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings()); + SNPRINTF(tempA, 300, tr("\t%s \n \t %lu/%lu"), currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings()); TVMediaInfo *info=new TVMediaInfo(); if (currentSubDir->recList.begin() != currentSubDir->recList.end()) @@ -126,15 +125,12 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) for (j = recList->begin(); j != recList->end(); j++) { currentRec = *j; - time_t recStartTime = (time_t)currentRec->getStartTime(); + time_t recStartTime = static_cast(currentRec->getStartTime()); LOCALTIME_R(&recStartTime, &btime); -//NMT does not like this too! - //#ifndef _MSC_VER -// strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); -//#else strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); -//#endif - sprintf(tempB, "%c\t%s\n \t%s", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(),tempA); + int check = SNPRINTF(tempB, 300, "%c\t%s\n \t%s", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(), tempA); + if ((check < 0) || (check > 299)) Log::getInstance()->log("VRecordingsListAdvanced", Log::ERR, "String too big"); + // New TVMedia stuff TVMediaInfo *info= new TVMediaInfo(); info->setPosterThumb(currentRec->getFileName()); @@ -163,7 +159,7 @@ void VRecordingListAdvanced::draw(bool doIndexPop) if (recman->isSubDir()) { char title[300]; - SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName()); + SNPRINTF(title, 300, tr("Recordings - %s"), recman->getCurDirName()); setTitleText(title, 364); } else @@ -173,7 +169,6 @@ void VRecordingListAdvanced::draw(bool doIndexPop) drawData(doIndexPop); } - TBBoxx::draw(); if (loading) @@ -184,7 +179,7 @@ void VRecordingListAdvanced::draw(bool doIndexPop) { char freeSpace[50]; int gigFree = recman->getFreeSpace() / 1024; - SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree); + SNPRINTF(freeSpace, 50, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree); drawTextRJ(freeSpace, 560+70, 5, DrawStyle::LIGHTTEXT); // Symbols @@ -220,7 +215,7 @@ void VRecordingListAdvanced::doShowingBar() rectangle(area.w/2-65, area.h-115, 180, 25, DrawStyle::VIEWBACKGROUND); #endif char showing[200]; - sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions()); + SNPRINTF(showing, 200, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions()); drawText(showing, area.w/2-65, area.h-35, DrawStyle::LIGHTTEXT); } @@ -286,7 +281,7 @@ void VRecordingListAdvanced::updateSelection() { currentRec = *j; - time_t recStartTime = (time_t)currentRec->getStartTime(); + time_t recStartTime = static_cast(currentRec->getStartTime()); LOCALTIME_R(&recStartTime, &btime); strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); diff --git a/vrecordinglistadvanced.h b/vrecordinglistadvanced.h index 1c4028c..c55edb6 100644 --- a/vrecordinglistadvanced.h +++ b/vrecordinglistadvanced.h @@ -14,18 +14,15 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VRECORDINGLIST_ADVANCED_H #define VRECORDINGLIST_ADVANCED_H - - -#include "vrecordinglist.h" #include "wtextbox.h" #include "wtvmedia.h" +#include "vrecordinglist.h" class VRecordingListAdvanced : public VRecordingList { @@ -33,7 +30,9 @@ class VRecordingListAdvanced : public VRecordingList VRecordingListAdvanced(); virtual ~VRecordingListAdvanced(); + using TBBoxx::draw; // Signal the compiler we are intentionally overriding the draw() virtual with different args void draw(bool doIndexPop = false); + bool load(); void drawData(bool doIndexPop = false); @@ -44,7 +43,6 @@ class VRecordingListAdvanced : public VRecordingList WTextbox epg; WTVMedia epgTVmedia; - }; #endif diff --git a/vrecordinglistclassic.cc b/vrecordinglistclassic.cc index 7f92a23..b577596 100644 --- a/vrecordinglistclassic.cc +++ b/vrecordinglistclassic.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2007 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,12 +14,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vrecordinglistclassic.h" - #include "recman.h" #include "directory.h" #include "recording.h" @@ -38,6 +35,8 @@ #include "vinfo.h" #include "log.h" +#include "vrecordinglistclassic.h" + VRecordingListClassic::VRecordingListClassic() { setSize(570, 420); @@ -84,7 +83,7 @@ void VRecordingListClassic::drawData(bool doIndexPop) for (i = dirList->begin(); i != dirList->end(); i++) { currentSubDir = *i; - SNPRINTF(tempA, 299, tr(" %lu/%lu\t \t%s"), currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name); + SNPRINTF(tempA, 300, tr(" %lu/%lu\t \t%s"), currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name); currentSubDir->index = sl.addOption(tempA, 0, first); first = 0; } @@ -96,15 +95,11 @@ void VRecordingListClassic::drawData(bool doIndexPop) for (j = recList->begin(); j != recList->end(); j++) { currentRec = *j; - time_t recStartTime = (time_t)currentRec->getStartTime(); + time_t recStartTime = static_cast(currentRec->getStartTime()); LOCALTIME_R(&recStartTime, &btime); -//NMT does not like this too! - //#ifndef _MSC_VER -// strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); -//#else - strftime(tempA, 299, "%d/%m %H:%M ", &btime); -//#endif - sprintf(tempB, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName()); + strftime(tempA, 300, "%d/%m %H:%M ", &btime); + int check = SNPRINTF(tempB, 300, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName()); + if ((check < 0) || (check > 299)) Log::getInstance()->log("VRecordingListClassic", Log::ERR, "String too big"); currentRec->index = sl.addOption(tempB, 0, first); first = 0; @@ -131,7 +126,7 @@ void VRecordingListClassic::draw(bool doIndexPop) if (recman->isSubDir()) { char title[300]; - SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName()); + SNPRINTF(title, 300, tr("Recordings - %s"), recman->getCurDirName()); setTitleText(title, 364); } else @@ -150,7 +145,7 @@ void VRecordingListClassic::draw(bool doIndexPop) { char freeSpace[50]; int gigFree = recman->getFreeSpace() / 1024; - SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree); + SNPRINTF(freeSpace, 50, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree); drawTextRJ(freeSpace, 560, 5, DrawStyle::LIGHTTEXT); // Symbols @@ -186,7 +181,7 @@ void VRecordingListClassic::doShowingBar() rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND); #endif char showing[200]; - sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions()); + SNPRINTF(showing, 200, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions()); drawText(showing, 220, 385, DrawStyle::LIGHTTEXT); } diff --git a/vrecordinglistclassic.h b/vrecordinglistclassic.h index 9676c59..2d056ca 100644 --- a/vrecordinglistclassic.h +++ b/vrecordinglistclassic.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,32 +14,29 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VRECORDINGLIST_CLASSIC_H #define VRECORDINGLIST_CLASSIC_H - - #include "vrecordinglist.h" - class VRecordingListClassic : public VRecordingList { public: VRecordingListClassic(); virtual ~VRecordingListClassic(); + using TBBoxx::draw; void draw(bool doIndexPop = false); + bool load(); void drawData(bool doIndexPop = false); protected: void quickUpdate(); void doShowingBar(); - }; #endif diff --git a/vscreensaver.cc b/vscreensaver.cc index 6e2e6e3..7355467 100644 --- a/vscreensaver.cc +++ b/vscreensaver.cc @@ -50,7 +50,7 @@ void VScreensaver::draw() threadStart(); } -int VScreensaver::handleCommand(int command) +int VScreensaver::handleCommand(int /*command*/) { threadCancel(); return 4; diff --git a/vtimerlist.cc b/vtimerlist.cc index b8eb713..c96c8b0 100644 --- a/vtimerlist.cc +++ b/vtimerlist.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,11 +14,13 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vtimerlist.h" +#include +#include +#include +#include #include "message.h" #include "input.h" @@ -30,24 +32,19 @@ #include "vtimeredit.h" #include "command.h" #include "boxstack.h" -#include "vdr.h" #include "vinfo.h" #include "log.h" #include "staticartwork.h" +#include "vtimerlist.h" + VTimerList::VTimerList() { - recTimerList = NULL; - clockRegion.x = 420; clockRegion.y = 0; clockRegion.w = 150; clockRegion.h = 30; - - - flipflop = true; - setSize(570, 420); createBuffer(); @@ -151,9 +148,10 @@ bool VTimerList::load() { recTimer = (*recTimerList)[i]; time_t rectime = recTimer->startTime; - LOCALTIME_R((time_t*)&rectime, &btime); + LOCALTIME_R(&rectime, &btime); strftime(strA, 299, "%d/%m %H:%M ", &btime); - SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName()); + int check = SNPRINTF(strB, 300, "%s\t%s", strA, recTimer->getName()); + if ((check < 0) || (check > 299)) Log::getInstance()->log("VTimerList", Log::ERR, "String too big"); sl.addOption(strB, recTimer, first); first = 0; } @@ -296,7 +294,7 @@ int VTimerList::handleCommand(int command) case Input::OK: { RecTimer* recTimer = NULL; - if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData(); + if (recTimerList) recTimer = reinterpret_cast(sl.getCurrentOptionData()); if (recTimer == NULL) return 2; VTimerEdit* v = new VTimerEdit(recTimer); @@ -339,7 +337,7 @@ void VTimerList::processMessage(Message* m) } else if (m->message == Message::DELETE_SELECTED_TIMER) { - RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData(); + RecTimer* recTimer = reinterpret_cast(sl.getCurrentOptionData()); if (recTimer == NULL) return; Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete"); diff --git a/vtimerlist.h b/vtimerlist.h index 8bd0d3b..21219bf 100644 --- a/vtimerlist.h +++ b/vtimerlist.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,20 +14,15 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VTIMERLIST_H #define VTIMERLIST_H -#include -#include -#include - +#include "vdr.h" #include "tbboxx.h" #include "timerreceiver.h" -#include "vdr.h" #include "wselectlist.h" #include "region.h" @@ -47,20 +42,17 @@ class VTimerList : public TBBoxx, public TimerReceiver void draw(); private: - RecTimerList* recTimerList; - - WSelectList sl; - void drawClock(); void drawShowing(); void drawData(); void drawIndicators(); void quickUpdate(); + RecTimerList* recTimerList{}; + WSelectList sl; + bool flipflop{true}; Region clockRegion; Region indicatorsRegion; - - bool flipflop; }; #endif -- 2.39.5