Skip to content

Commit

Permalink
More const fixes, this time from suggestions from VS code analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed Dec 20, 2024
1 parent c7acb9d commit debec03
Show file tree
Hide file tree
Showing 44 changed files with 130 additions and 152 deletions.
10 changes: 5 additions & 5 deletions src/common/FBBackendSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void FBBackendSDL2::queryHardware(vector<Common::Size>& fullscreenRes,
myNumDisplays = SDL_GetNumVideoDisplays();

// First get the maximum fullscreen desktop resolution
SDL_DisplayMode display;
SDL_DisplayMode display{};
for(int i = 0; i < myNumDisplays; ++i)
{
SDL_GetDesktopDisplayMode(i, &display);
Expand Down Expand Up @@ -133,7 +133,7 @@ void FBBackendSDL2::queryHardware(vector<Common::Size>& fullscreenRes,
SDL_DestroyWindow(tmpWindow);
}

SDL_Rect r;
SDL_Rect r{};
for(int i = 0; i < myNumDisplays; ++i)
{
// Display bounds minus dock
Expand Down Expand Up @@ -261,7 +261,7 @@ bool FBBackendSDL2::setVideoMode(const VideoModeHandler::Mode& mode,
}

#ifdef ADAPTABLE_REFRESH_SUPPORT
SDL_DisplayMode adaptedSdlMode;
SDL_DisplayMode adaptedSdlMode{};
const int gameRefreshRate =
myOSystem.hasConsole() ? myOSystem.console().gameRefreshRate() : 0;
const bool shouldAdapt = fullScreen
Expand Down Expand Up @@ -374,7 +374,7 @@ bool FBBackendSDL2::adaptRefreshRate(Int32 displayIndex,
// Check for integer factors 1 (60/50 Hz) and 2 (120/100 Hz)
for(int m = 1; m <= 2; ++m)
{
SDL_DisplayMode closestSdlMode;
SDL_DisplayMode closestSdlMode{};

sdlMode.refresh_rate = wantedRefreshRate * m;
if(SDL_GetClosestDisplayMode(displayIndex, &sdlMode, &closestSdlMode) == nullptr)
Expand Down Expand Up @@ -416,7 +416,7 @@ bool FBBackendSDL2::createRenderer()
bool recreate = myRenderer == nullptr;
uInt32 renderFlags = SDL_RENDERER_ACCELERATED;
const string& video = myOSystem.settings().getString("video"); // Render hint
SDL_RendererInfo renderInfo;
SDL_RendererInfo renderInfo{};

if(myOSystem.settings().getBool("vsync")
&& !myOSystem.settings().getBool("turbo")) // V'synced blits option
Expand Down
2 changes: 1 addition & 1 deletion src/common/HighScoresManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class HighScoresManager
@return The number of score address bytes
*/
static uInt32 numAddrBytes(Int32 digits, Int32 trailing) {
static constexpr uInt32 numAddrBytes(Int32 digits, Int32 trailing) {
return (digits - trailing + 1) / 2;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/SoundSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void SoundSDL2::initResampler()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL2::callback(void* object, uInt8* stream, int len)
{
auto* self = static_cast<SoundSDL2*>(object);
const auto* self = static_cast<SoundSDL2*>(object);

if(self->myAudioQueue && self->myResampler)
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/StellaKeys.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ namespace StellaKeyName
inline string_view forKey(StellaKey key)
{
#ifdef SDL_SUPPORT
return SDL_GetScancodeName(SDL_Scancode(key));
return SDL_GetScancodeName(static_cast<SDL_Scancode>(key));
#else
return string_view{};
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/common/bspf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace BSPF
try {
int i{};
s = s.substr(s.find_first_not_of(' '));
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
const auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
return result.ec == std::errc() ? i : defaultValue;
}
catch(...) { return defaultValue; }
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace BSPF
}

// Test whether the first string contains the second one (case insensitive)
inline constexpr bool containsIgnoreCase(string_view s1, string_view s2)
constexpr bool containsIgnoreCase(string_view s1, string_view s2)
{
return findIgnoreCase(s1, s2) != string::npos;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void checkForCustomBaseDir(Settings::Options& options)
OSystem::overrideBaseDirWithApp();
else
{
auto it = options.find("basedir");
const auto it = options.find("basedir");
if(it != options.end())
OSystem::overrideBaseDir(it->second.toString());
}
Expand Down Expand Up @@ -161,7 +161,7 @@ void attachConsole()
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hConsole, &csbi))
{
COORD pos = {0, csbi.dwCursorPosition.Y};
const COORD pos = {0, csbi.dwCursorPosition.Y};
SetConsoleCursorPosition(hConsole, pos);
cout << std::setw(160) << ""; // this clears the extra prompt display
SetConsoleCursorPosition(hConsole, pos);
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/CartDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bool CartDebug::fillDisassemblyList(BankInfo& info, Disassembly& disassembly,

disassembly.fieldwidth = 24 + myLabelLength;
// line offset must be set before calling DiStella!
auto lineOfs = static_cast<uInt32>(myDisassembly.list.size());
const auto lineOfs = static_cast<uInt32>(myDisassembly.list.size());
const DiStella distella(*this, disassembly.list, info, DiStella::settings,
myDisLabels, myDisDirectives, myReserved);

Expand Down Expand Up @@ -1209,7 +1209,7 @@ string CartDebug::saveDisassembly(string path)
cart.lockHotspots();

// Some boilerplate, similar to what DiStella adds
auto timeinfo = BSPF::localTime();
const auto timeinfo = BSPF::localTime();
stringstream out;
out << "; Disassembly of " << myOSystem.romFile().getShortPath() << "\n"
<< "; Disassembled " << std::put_time(&timeinfo, "%c\n")
Expand Down
6 changes: 3 additions & 3 deletions src/debugger/DebuggerParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ void DebuggerParser::executeSaveRom()
void DebuggerParser::executeSaveSes()
{
ostringstream filename; // NOLINT (filename is not a const)
auto timeinfo = BSPF::localTime();
const auto timeinfo = BSPF::localTime();
filename << std::put_time(&timeinfo, "session_%F_%H-%M-%S.txt");

if(argCount && argStrings[0] == "?")
Expand Down Expand Up @@ -2356,8 +2356,8 @@ void DebuggerParser::executeTimer()
}

uInt32 numAddrs = 0, numBanks = 0;
uInt16 addr[2];
uInt8 bank[2];
uInt16 addr[2]{};
uInt8 bank[2]{};

// set defaults:
addr[0] = debugger.cpuDebug().pc() ;
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/TimerMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ uInt32 TimerMap::add(uInt16 addr, uInt8 bank, bool mirrors, bool anyBank)
// update tp key in myFromMap for new mirrors & anyBank settings
// 1. find map entry using OLD tp key settings:
toKey(tpFrom, oldMirrors, oldAnyBank);
auto from = myFromMap.equal_range(tpFrom);
const auto from = myFromMap.equal_range(tpFrom);
for(auto it = from.first; it != from.second; ++it)
if(it->second == &tmPartial)
{
Expand Down
5 changes: 3 additions & 2 deletions src/debugger/gui/AudioWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ AudioWidget::AudioWidget(GuiObject* boss, const GUI::Font& lfont,
{
const int fontWidth = lfont.getMaxCharWidth(),
fontHeight = lfont.getFontHeight(),
lineHeight = lfont.getLineHeight();
int xpos = 10, ypos = 25, lwidth = lfont.getStringWidth("AUDW ");
lineHeight = lfont.getLineHeight(),
lwidth = lfont.getStringWidth("AUDW ");
int xpos = 10, ypos = 25;

// AudF registers
new StaticTextWidget(boss, lfont, xpos, ypos+2,
Expand Down
9 changes: 5 additions & 4 deletions src/debugger/gui/BoosterWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ BoosterWidget::BoosterWidget(GuiObject* boss, const GUI::Font& font,
{
const string& label = isLeftPort() ? "Left (Booster)" : "Right (Booster)";

const int fontHeight = font.getFontHeight();
int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Booster)");
auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);
const int fontHeight = font.getFontHeight(),
lwidth = font.getStringWidth("Right (Booster)");
int xpos = x, ypos = y;
const auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);
xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 10;
myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "",
CheckboxWidget::kCheckActionCmd);
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/gui/Cart3EPlusWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
label.str("");
label << "$" << Common::Base::HEX4 << addr1 << "-$"
<< Common::Base::HEX4 << (addr1 + 0x1FF);
auto* t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.view());
const auto* t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.view());

const int xoffset = t->getRight() + _font.getMaxCharWidth();
const size_t bank_off = static_cast<size_t>(seg) * 2;
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/gui/Cart3EWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Cartridge3EWidget::bankSelect(int& ypos)
myBankWidgets[0]->setID(0);
addFocusWidget(myBankWidgets[0]);

auto* t = new StaticTextWidget(_boss, _font,
const auto* t = new StaticTextWidget(_boss, _font,
myBankWidgets[0]->getRight(), ypos - 1, " (ROM)");

xpos = t->getRight() + 20;
Expand Down
3 changes: 2 additions & 1 deletion src/debugger/gui/CartELFStateWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void CartridgeELFStateWidget::loadConfig()
s << myCart.myTransactionQueue.size();
myQueueSize->setText(s.str());

BusTransactionQueue::Transaction* nextTransaction = myCart.myTransactionQueue.peekNextTransaction();
const BusTransactionQueue::Transaction* nextTransaction =
myCart.myTransactionQueue.peekNextTransaction();
myNextTransaction->setLabel(nextTransaction
? describeTransaction(
nextTransaction->address,
Expand Down
7 changes: 3 additions & 4 deletions src/debugger/gui/CartFA2Widget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ CartridgeFA2Widget::CartridgeFA2Widget(
myCartFA2{cart}
{
int xpos = 2;
const int ypos = initialize() + 12;
const int ypos = initialize() + 12,
bwidth = _font.getStringWidth("Erase") + 20;

const int bwidth = _font.getStringWidth("Erase") + 20;

auto* t = new StaticTextWidget(boss, _font, xpos, ypos,
const auto* t = new StaticTextWidget(boss, _font, xpos, ypos,
_font.getStringWidth("Harmony flash memory "),
myFontHeight, "Harmony flash memory ", TextAlign::Left);

Expand Down
7 changes: 4 additions & 3 deletions src/debugger/gui/GenesisWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ GenesisWidget::GenesisWidget(GuiObject* boss, const GUI::Font& font,
{
const string& label = getHeader();

const int fontHeight = font.getFontHeight();
int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Genesis)");
const int fontHeight = font.getFontHeight(),
lwidth = font.getStringWidth("Right (Genesis)");
int xpos = x, ypos = y;

const StaticTextWidget* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);
fontHeight, label, TextAlign::Left);
xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 20;
myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "",
CheckboxWidget::kCheckActionCmd);
Expand Down
9 changes: 5 additions & 4 deletions src/debugger/gui/Joy2BPlusWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Joy2BPlusWidget::Joy2BPlusWidget(GuiObject* boss, const GUI::Font& font,
{
const string& label = isLeftPort() ? "Left (Joy 2B+)" : "Right (Joy 2B+)";

const int fontHeight = font.getFontHeight();
int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Joy 2B+)");
auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);
const int fontHeight = font.getFontHeight(),
lwidth = font.getStringWidth("Right (Joy 2B+)");
int xpos = x, ypos = y;
const auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);
xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 10;
myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "",
CheckboxWidget::kCheckActionCmd);
Expand Down
5 changes: 3 additions & 2 deletions src/debugger/gui/KeyboardWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font,
const bool leftport = isLeftPort();
const string& label = leftport ? "Left (Keyboard)" : "Right (Keyboard)";

const int fontHeight = font.getFontHeight();
int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Keyboard)");
const int fontHeight = font.getFontHeight(),
lwidth = font.getStringWidth("Right (Keyboard)");
int xpos = x, ypos = y;
const StaticTextWidget* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, TextAlign::Left);

Expand Down
7 changes: 3 additions & 4 deletions src/debugger/gui/PaddleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, int x, int y,
{
const bool leftport = isLeftPort();
const string& label = getHeader();
const int fontHeight = font.getFontHeight();

int xpos = x, ypos = y,
lwidth = font.getStringWidth("Right (Paddles)");
const int fontHeight = font.getFontHeight(),
lwidth = font.getStringWidth("Right (Paddles)");
int xpos = x, ypos = y;

if(!embedded)
{
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/gui/RomWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
{
// Show current bank state
int xpos = x, ypos = y + 7;
auto* t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info ");
const auto* t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info ");

xpos += t->getRight();
myBank = new EditTextWidget(boss, nfont, xpos, ypos-2,
Expand Down Expand Up @@ -90,7 +90,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
case RomListWidget::kRomChangedCmd:
// 'data' is the line in the disassemblylist to be accessed
// 'id' is the base to use for the data to be changed
patchROM(data, myRomList->getText(), Common::Base::Fmt(id));
patchROM(data, myRomList->getText(), static_cast<Common::Base::Fmt>(id));
break;

case RomListWidget::kSetPCCmd:
Expand Down
8 changes: 4 additions & 4 deletions src/emucore/CartELF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ string CartridgeELF::getDebugLog() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::pair<unique_ptr<uInt8[]>, size_t> CartridgeELF::getArmImage() const
{
const size_t imageSize = ADDR_TABLES_BASE + TABLES_SIZE;
constexpr size_t imageSize = ADDR_TABLES_BASE + TABLES_SIZE;
unique_ptr<uInt8[]> image = make_unique<uInt8[]>(imageSize);

memset(image.get(), 0, imageSize);
Expand All @@ -430,7 +430,7 @@ std::pair<unique_ptr<uInt8[]>, size_t> CartridgeELF::getArmImage() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt8 CartridgeELF::driveBus(uInt16 address, uInt8 value)
{
auto* nextTransaction = myTransactionQueue.getNextTransaction(address,
const auto* nextTransaction = myTransactionQueue.getNextTransaction(address,
mySystem->cycles() * myArmCyclesPer6502Cycle - myArmCyclesOffset);
if (nextTransaction) {
nextTransaction->setBusState(myIsBusDriven, myDriveBusValue);
Expand Down Expand Up @@ -459,7 +459,7 @@ void CartridgeELF::parseAndLinkElf()

try {
myElfParser.parse(myImage.get(), myImageSize);
} catch (ElfParser::ElfParseError& e) {
} catch (const ElfParser::ElfParseError& e) {
throw runtime_error("failed to initialize ELF: " + string(e.what()));
}

Expand Down Expand Up @@ -695,7 +695,7 @@ void CartridgeELF::BusFallbackDelegate::setErrorsAreFatal(bool fatal)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CartridgeELF::BusFallbackDelegate::handleError(
string_view accessType, uInt32 address, CortexM0::err_t err, CortexM0& cortex
string_view accessType, uInt32 address, CortexM0::err_t err, const CortexM0& cortex
) const {
if (myErrorsAreFatal) return CortexM0::errIntrinsic(err, address);

Expand Down
2 changes: 1 addition & 1 deletion src/emucore/CartELF.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CartridgeELF: public Cartridge {

private:
CortexM0::err_t handleError(
string_view accessType, uInt32 address, CortexM0::err_t err, CortexM0& cortex
string_view accessType, uInt32 address, CortexM0::err_t err, const CortexM0& cortex
) const;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/Console.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ FBInitStatus Console::initializeVideo(bool full)

if(full)
{
auto size = myOSystem.settings().getBool("tia.correct_aspect") ?
const auto size = myOSystem.settings().getBool("tia.correct_aspect") ?
Common::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight) :
Common::Size(2 * myTIA->width(), myTIA->height());

Expand Down
Loading

0 comments on commit debec03

Please sign in to comment.