Convert some raw arrays to std::array.

Some fixes for warnings from Coverity.
This commit is contained in:
Stephen Anthony 2019-11-14 20:12:45 -03:30
parent f08bc8843d
commit 025eeba38c
16 changed files with 133 additions and 88 deletions

View File

@ -33,7 +33,9 @@ static constexpr char CTRL_DELIM = '^';
PhysicalJoystickHandler::PhysicalJoystickHandler(
OSystem& system, EventHandler& handler)
: myOSystem(system),
myHandler(handler)
myHandler(handler),
myLeftMode(EventMode::kEmulationMode),
myRightMode(EventMode::kEmulationMode)
{
Int32 version = myOSystem.settings().getInt("event_ver");
// Load previously saved joystick mapping (if any) from settings

View File

@ -42,7 +42,9 @@ static constexpr int MOD3 = KBDM_ALT;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalKeyboardHandler::PhysicalKeyboardHandler(OSystem& system, EventHandler& handler)
: myOSystem(system),
myHandler(handler)
myHandler(handler),
myLeftMode(EventMode::kEmulationMode),
myRightMode(EventMode::kEmulationMode)
#ifdef BSPF_UNIX
, myAltKeyCounter(0)
#endif

View File

@ -46,8 +46,10 @@ StaggeredLogger::StaggeredLogger(const string& message, Logger::Level level)
myCurrentIntervalFactor(1),
myCooldownTime(1000),
myTimer(new TimerManager()),
myTimerId(0),
myTimerCallbackId(0)
{}
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StaggeredLogger::~StaggeredLogger()

View File

@ -26,13 +26,15 @@
#include "bspf.hxx"
#include "TimerManager.hxx"
#include "Logger.hxx"
/**
* This class buffers log events and logs them after a certain time window has expired.
* The timout increases after every log line by a factor of two until a maximum is reached.
* If no events are reported, the window size decreases again.
*/
class StaggeredLogger {
class StaggeredLogger
{
public:
StaggeredLogger(const string& message, Logger::Level level);

View File

@ -167,8 +167,16 @@ int main(int ac, char* av[])
if (isProfilingRun(ac, av)) {
ProfilingRunner runner(ac, av);
try
{
return runner.run() ? 0 : 1;
}
catch(const runtime_error& e)
{
cerr << e.what() << endl;
return 0;
}
}
unique_ptr<OSystem> theOSystem;

View File

@ -49,7 +49,7 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font,
myZoomLevel = 2;
myNumCols = (_w - 4) / myZoomLevel;
myNumRows = (_h - 4) / myZoomLevel;
myOffX = myOffY = 0;
myOffX = myOffY = myOffXLo = myOffYLo = 0;
myMouseMoving = false;
myClickX = myClickY = 0;

View File

@ -123,7 +123,8 @@ void CartridgeCDF::setInitialState()
myMode = 0xFF;
myBankOffset = myLDAimmediateOperandAddress = myJMPoperandAddress = 0;
myFastJumpActive = 0;
myFastJumpActive = myFastJumpStream = 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -26,7 +26,8 @@ CartridgeDPC::CartridgeDPC(const ByteBuffer& image, size_t size,
mySize(size),
myAudioCycles(0),
myFractionalClocks(0.0),
myBankOffset(0)
myBankOffset(0),
myDpcPitch(0.0)
{
// Make a copy of the entire image
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin());

View File

@ -821,7 +821,7 @@ void Console::setControllers(const string& romMd5)
const bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES";
// Try to detect controllers
if(image != nullptr || size != 0)
if(image != nullptr && size != 0)
{
leftType = ControllerDetector::detectType(image, size, leftType,
!swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, myOSystem.settings());

View File

@ -242,14 +242,14 @@ void EventHandler::poll(uInt64 time)
myOSystem.png().updateTime(time);
#endif
}
#ifdef GUI_SUPPORT
else if(myOverlay)
{
#ifdef GUI_SUPPORT
// Update the current dialog container at regular intervals
// Used to implement continuous events
myOverlay->updateTime(time);
#endif
}
#endif
// Turn off all mouse-related items; if they haven't been taken care of
// in the previous ::update() methods, they're now invalid
@ -1006,28 +1006,14 @@ bool EventHandler::changeStateByEvent(Event::Type type)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setActionMappings(EventMode mode)
{
int listsize = 0;
ActionList* list = nullptr;
switch(mode)
{
case EventMode::kEmulationMode:
listsize = EMUL_ACTIONLIST_SIZE;
list = ourEmulActionList;
break;
case EventMode::kMenuMode:
listsize = MENU_ACTIONLIST_SIZE;
list = ourMenuActionList;
break;
default:
return;
}
// Fill the ActionList with the current key and joystick mappings
for(int i = 0; i < listsize; ++i)
// Fill the EmulActionList with the current key and joystick mappings
for(auto& item: ourEmulActionList)
{
Event::Type event = list[i].event;
list[i].key = "None";
Event::Type event = item.event;
item.key = "None";
string key = myPKeyHandler->getMappingDesc(event, mode);
#ifdef JOYSTICK_SUPPORT
@ -1041,7 +1027,33 @@ void EventHandler::setActionMappings(EventMode mode)
#endif
if(key != "")
list[i].key = key;
item.key = key;
}
break;
case EventMode::kMenuMode:
// Fill the MenuActionList with the current key and joystick mappings
for(auto& item: ourMenuActionList)
{
Event::Type event = item.event;
item.key = "None";
string key = myPKeyHandler->getMappingDesc(event, mode);
#ifdef JOYSTICK_SUPPORT
string joydesc = myPJoyHandler->getMappingDesc(event, mode);
if(joydesc != "")
{
if(key != "")
key += ", ";
key += joydesc;
}
#endif
if(key != "")
item.key = key;
}
break;
default:
return;
}
}
@ -1222,12 +1234,12 @@ StringList EventHandler::getActionList(EventMode mode) const
switch(mode)
{
case EventMode::kEmulationMode:
for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i)
l.push_back(EventHandler::ourEmulActionList[i].action);
for(const auto& item: ourEmulActionList)
l.push_back(item.action);
break;
case EventMode::kMenuMode:
for(uInt32 i = 0; i < MENU_ACTIONLIST_SIZE; ++i)
l.push_back(EventHandler::ourMenuActionList[i].action);
for(const auto& item: ourMenuActionList)
l.push_back(item.action);
break;
default:
break;
@ -1288,21 +1300,21 @@ StringList EventHandler::getActionList(const Event::EventSet& events, EventMode
switch(mode)
{
case EventMode::kMenuMode:
for(uInt32 i = 0; i < MENU_ACTIONLIST_SIZE; ++i)
for(const auto& item: ourMenuActionList)
for(const auto& event : events)
if(EventHandler::ourMenuActionList[i].event == event)
if(item.event == event)
{
l.push_back(EventHandler::ourMenuActionList[i].action);
l.push_back(item.action);
break;
}
break;
default:
for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i)
for(const auto& item: ourEmulActionList)
for(const auto& event : events)
if(EventHandler::ourEmulActionList[i].event == event)
if(item.event == event)
{
l.push_back(EventHandler::ourEmulActionList[i].action);
l.push_back(item.action);
break;
}
}
@ -1317,7 +1329,7 @@ VariantList EventHandler::getComboList(EventMode /**/) const
ostringstream buf;
VarList::push_back(l, "None", "-1");
for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i)
for(uInt32 i = 0; i < ourEmulActionList.size(); ++i)
{
Event::Type event = EventHandler::ourEmulActionList[i].event;
// exclude combos events
@ -1342,7 +1354,7 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const
for(uInt32 i = 0; i < EVENTS_PER_COMBO; ++i)
{
Event::Type e = myComboTable[combo][i];
for(uInt32 j = 0; j < EMUL_ACTIONLIST_SIZE; ++j)
for(uInt32 j = 0; j < ourEmulActionList.size(); ++j)
{
if(EventHandler::ourEmulActionList[j].event == e)
{
@ -1366,10 +1378,10 @@ void EventHandler::setComboListForEvent(Event::Type event, const StringList& eve
{
assert(events.size() == 8);
int combo = event - Event::Combo1;
for(int i = 0; i < 8; ++i)
for(uInt32 i = 0; i < 8; ++i)
{
int idx = atoi(events[i].c_str());
if(idx >= 0 && idx < EMUL_ACTIONLIST_SIZE)
uInt32 idx = atoi(events[i].c_str());
if(idx < ourEmulActionList.size())
myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event;
else
myComboTable[combo][i] = Event::NoType;
@ -1385,7 +1397,7 @@ int EventHandler::getEmulActionListIndex(int idx, const Event::EventSet& events)
// ordered by 'ourEmulActionList'!
Event::Type event = Event::NoType;
for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i)
for(uInt32 i = 0; i < ourEmulActionList.size(); ++i)
{
for(const auto& item : events)
if(EventHandler::ourEmulActionList[i].event == item)
@ -1399,7 +1411,7 @@ int EventHandler::getEmulActionListIndex(int idx, const Event::EventSet& events)
break;
}
for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i)
for(uInt32 i = 0; i < ourEmulActionList.size(); ++i)
if(EventHandler::ourEmulActionList[i].event == event)
return i;
@ -1457,13 +1469,13 @@ Event::Type EventHandler::eventAtIndex(int idx, Event::Group group) const
switch(group)
{
case Event::Group::Menu:
if(index < 0 || index >= MENU_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourMenuActionList.size()))
return Event::NoType;
else
return ourMenuActionList[index].event;
default:
if(index < 0 || index >= EMUL_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourEmulActionList.size()))
return Event::NoType;
else
return ourEmulActionList[index].event;
@ -1478,13 +1490,13 @@ string EventHandler::actionAtIndex(int idx, Event::Group group) const
switch(group)
{
case Event::Group::Menu:
if(index < 0 || index >= MENU_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourMenuActionList.size()))
return EmptyString;
else
return ourMenuActionList[index].action;
default:
if(index < 0 || index >= EMUL_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourEmulActionList.size()))
return EmptyString;
else
return ourEmulActionList[index].action;
@ -1499,13 +1511,13 @@ string EventHandler::keyAtIndex(int idx, Event::Group group) const
switch(group)
{
case Event::Group::Menu:
if(index < 0 || index >= MENU_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourMenuActionList.size()))
return EmptyString;
else
return ourMenuActionList[index].key;
default:
if(index < 0 || index >= EMUL_ACTIONLIST_SIZE)
if(index < 0 || index >= int(ourEmulActionList.size()))
return EmptyString;
else
return ourEmulActionList[index].key;
@ -1710,7 +1722,7 @@ void EventHandler::exitEmulation()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = {
EventHandler::EmulActionList EventHandler::ourEmulActionList = { {
{ Event::Quit, "Quit", "" },
{ Event::ReloadConsole, "Reload current ROM/load next game", "" },
{ Event::ExitMode, "Exit current Stella menu/mode", "" },
@ -1887,10 +1899,10 @@ EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] =
{ Event::Combo14, "Combo 14", "" },
{ Event::Combo15, "Combo 15", "" },
{ Event::Combo16, "Combo 16", "" }
};
} };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::ActionList EventHandler::ourMenuActionList[MENU_ACTIONLIST_SIZE] = {
EventHandler::MenuActionList EventHandler::ourMenuActionList = { {
{ Event::UIUp, "Move Up", "" },
{ Event::UIDown, "Move Down", "" },
{ Event::UILeft, "Move Left", "" },
@ -1913,7 +1925,7 @@ EventHandler::ActionList EventHandler::ourMenuActionList[MENU_ACTIONLIST_SIZE] =
{ Event::UIPrevDir, "Parent directory", "" },
{ Event::ToggleFullScreen, "Toggle fullscreen", "" },
{ Event::Quit, "Quit", "" }
};
} };
// Event groups
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -388,18 +388,6 @@ class EventHandler
void removePhysicalJoystick(int index);
private:
static constexpr Int32
COMBO_SIZE = 16,
EVENTS_PER_COMBO = 8,
#ifdef PNG_SUPPORT
PNG_SIZE = 2,
#else
PNG_SIZE = 0,
#endif
EMUL_ACTIONLIST_SIZE = 139 + PNG_SIZE + COMBO_SIZE,
MENU_ACTIONLIST_SIZE = 18
;
// Define event groups
static const Event::EventSet MiscEvents;
static const Event::EventSet AudioVideoEvents;
@ -449,9 +437,6 @@ class EventHandler
// all possible controller modes
unique_ptr<MouseControl> myMouseControl;
// The event(s) assigned to each combination event
Event::Type myComboTable[COMBO_SIZE][EVENTS_PER_COMBO];
// Indicates the current state of the system (ie, which mode is current)
EventHandlerState myState;
@ -469,9 +454,28 @@ class EventHandler
// of the 7800 (for now, only the switches are notified)
bool myIs7800;
// These constants are not meant to be used elsewhere; they are only used
// here to make it easier for the reader to correctly size the list(s)
static constexpr Int32
COMBO_SIZE = 16,
EVENTS_PER_COMBO = 8,
#ifdef PNG_SUPPORT
PNG_SIZE = 3,
#else
PNG_SIZE = 0,
#endif
EMUL_ACTIONLIST_SIZE = 138 + PNG_SIZE + COMBO_SIZE,
MENU_ACTIONLIST_SIZE = 18
;
// The event(s) assigned to each combination event
Event::Type myComboTable[COMBO_SIZE][EVENTS_PER_COMBO];
// Holds static strings for the remap menu (emulation and menu events)
static ActionList ourEmulActionList[EMUL_ACTIONLIST_SIZE];
static ActionList ourMenuActionList[MENU_ACTIONLIST_SIZE];
using EmulActionList = std::array<ActionList, EMUL_ACTIONLIST_SIZE>;
static EmulActionList ourEmulActionList;
using MenuActionList = std::array<ActionList, MENU_ACTIONLIST_SIZE>;
static MenuActionList ourMenuActionList;
// Following constructors and assignment operators not supported
EventHandler() = delete;

View File

@ -56,7 +56,8 @@ FrameBuffer::FrameBuffer(OSystem& osystem)
myGrabMouse(false),
myHiDPIAllowed(false),
myHiDPIEnabled(false),
myCurrentModeList(nullptr)
myCurrentModeList(nullptr),
myTIAMaxZoom(1.0)
{
}

View File

@ -178,7 +178,7 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
EmulationTiming emulationTiming(frameLayout, consoleTiming);
uInt64 cycles = 0;
uInt64 cyclesTarget = run.runtime * emulationTiming.cyclesPerSecond();
uInt64 cyclesTarget = uInt64(run.runtime) * emulationTiming.cyclesPerSecond();
DispatchResult dispatchResult;
dispatchResult.setOk(0);

View File

@ -44,7 +44,10 @@ FrameLayout FrameLayoutDetector::detectedLayout() const{
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameLayoutDetector::FrameLayoutDetector()
: myState(State::waitForVsyncStart)
: myState(State::waitForVsyncStart),
myNtscFrames(0),
myPalFrames(0),
myLinesWaitingForVsyncToStart(0)
{
reset();
}

View File

@ -50,6 +50,11 @@ enum Metrics: uInt32 {
YStartDetector::YStartDetector()
: myState(State::waitForVsyncStart),
myVblankMode(VblankMode::floating),
myLinesWaitingForVsyncToStart(0),
myCurrentVblankLines(0),
myLastVblankLines(0),
myVblankViolations(0),
myStableVblankFrames(0),
myVblankViolated(false)
{
reset();

View File

@ -51,6 +51,8 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font,
myLastAxis(JoyAxis::NONE),
myLastDir(JoyDir::NONE),
myLastHatDir(JoyHatDir::CENTER),
myMod(0),
myLastKey(0),
myLastButton(JOY_CTRL_NONE),
myFirstTime(true)
{