diff --git a/src/common/EventHandlerSDL2.cxx b/src/common/EventHandlerSDL2.cxx index e4d148fb9..6963d29d5 100644 --- a/src/common/EventHandlerSDL2.cxx +++ b/src/common/EventHandlerSDL2.cxx @@ -268,7 +268,7 @@ EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx) // it also appends " #x", where x seems to vary. Obviously this wreaks // havoc with the idea that a joystick will always have the same name. // So we truncate the number. - const char* sdlname = SDL_JoystickName(myStick); + const char* const sdlname = SDL_JoystickName(myStick); const string& desc = BSPF::startsWithIgnoreCase(sdlname, "XInput Controller") ? "XInput Controller" : sdlname; diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 891d77945..a41cbdd29 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -39,7 +39,7 @@ FSNodeZIP::FSNodeZIP(const string& p) if (_zipFile[0] == '~') { #if defined(BSPF_UNIX) || defined(BSPF_MACOS) - const char* home = std::getenv("HOME"); // NOLINT (not thread safe) + const char* const home = std::getenv("HOME"); // NOLINT (not thread safe) if (home != nullptr) _zipFile.replace(0, 1, home); #elif defined(BSPF_WINDOWS) @@ -270,8 +270,8 @@ AbstractFSNodePtr FSNodeZIP::getParent() const if(_virtualPath.empty()) return _realNode ? _realNode->getParent() : nullptr; - const char* start = _path.c_str(); - const char* end = lastPathComponent(_path); + const char* const start = _path.c_str(); + const char* const end = lastPathComponent(_path); return make_unique(string(start, end - start - 1)); } diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 3bee69bcf..af1491763 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -120,7 +120,9 @@ bool SoundSDL2::openDevice() myDeviceId = BSPF::clamp(myAudioSettings.device(), 0U, static_cast(myDevices.size() - 1)); - const char* device = myDeviceId ? myDevices.at(myDeviceId).first.c_str() : nullptr; + const char* const device = myDeviceId + ? myDevices.at(myDeviceId).first.c_str() + : nullptr; myDevice = SDL_OpenAudioDevice(device, 0, &desired, &myHardwareSpec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); @@ -384,7 +386,9 @@ void SoundSDL2::callback(void* object, uInt8* stream, int len) bool SoundSDL2::playWav(const string& fileName, const uInt32 position, const uInt32 length) { - const char* device = myDeviceId ? myDevices.at(myDeviceId).first.c_str() : nullptr; + const char* const device = myDeviceId + ? myDevices.at(myDeviceId).first.c_str() + : nullptr; return myWavHandler.play(fileName, device, position, length); } diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 67547ceda..4c7b60192 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -845,7 +845,7 @@ string CartDebug::loadListFile() buf >> addr >> addr_s; if(addr_s.length() == 0) continue; - const char* p = addr_s[0] == 'U' ? addr_s.c_str() + 1 : addr_s.c_str(); + const char* const p = addr_s[0] == 'U' ? addr_s.c_str() + 1 : addr_s.c_str(); addr = static_cast(strtoul(p, nullptr, 16)); // For now, completely ignore ROM addresses @@ -1555,7 +1555,7 @@ void CartDebug::getCompletions(const char* in, StringList& completions) const // Now scan user-defined labels for(const auto& iter: myUserAddresses) { - const char* l = iter.first.c_str(); + const char* const l = iter.first.c_str(); if(BSPF::matchesCamelCase(l, in)) completions.push_back(l); } diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index ad39ae5e3..dda3774e1 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -899,7 +899,7 @@ void Debugger::getCompletions(const char* in, StringList& list) const { for(const auto& iter : myFunctions) { - const char* l = iter.first.c_str(); + const char* const l = iter.first.c_str(); if(BSPF::matchesCamelCase(l, in)) list.push_back(l); } diff --git a/src/emucore/FSNode.hxx b/src/emucore/FSNode.hxx index aff2986a6..66342eada 100644 --- a/src/emucore/FSNode.hxx +++ b/src/emucore/FSNode.hxx @@ -509,7 +509,7 @@ class AbstractFSNode if(str.empty()) return ""; - const char* start = str.c_str(); + const char* const start = str.c_str(); const char* cur = start + str.size() - 2; while (cur >= start && !(*cur == '/' || *cur == '\\')) diff --git a/src/emucore/KidVid.cxx b/src/emucore/KidVid.cxx index 085e01349..7170c031b 100644 --- a/src/emucore/KidVid.cxx +++ b/src/emucore/KidVid.cxx @@ -118,7 +118,7 @@ void KidVid::update() if(myTape) { static constexpr uInt32 gameNumber[4] = { 3, 1, 2, 3 }; - static constexpr const char* gameName[6] = { + static constexpr const char* const gameName[6] = { "Harmony Smurf", "Handy Smurf", "Greedy Smurf", "Big Number Hunt", "Great Letter Roundup", "Spooky Spelling Bee" }; @@ -240,7 +240,7 @@ bool KidVid::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const char* KidVid::getFileName() const { - static constexpr const char* fileNames[6] = { + static constexpr const char* const fileNames[6] = { "KVS3.WAV", "KVS1.WAV", "KVS2.WAV", "KVB3.WAV", "KVB1.WAV", "KVB2.WAV" }; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index ff182a041..095898426 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -527,7 +527,7 @@ string OSystem::createConsole(const FSNode& rom, const string& md5sum, { // Make sure there always is an id constexpr int ID_LEN = 32; - const char* HEX_DIGITS = "0123456789ABCDEF"; + const char* const HEX_DIGITS = "0123456789ABCDEF"; char id_chr[ID_LEN] = { 0 }; const Random rnd; diff --git a/src/os/unix/OSystemUNIX.cxx b/src/os/unix/OSystemUNIX.cxx index 28de8144b..91409c2ae 100644 --- a/src/os/unix/OSystemUNIX.cxx +++ b/src/os/unix/OSystemUNIX.cxx @@ -26,7 +26,7 @@ void OSystemUNIX::getBaseDirectories(string& basedir, string& homedir, bool useappdir, const string& usedir) { // Use XDG_CONFIG_HOME if defined, otherwise use the default - const char* cfg_home = std::getenv("XDG_CONFIG_HOME"); // NOLINT + const char* const cfg_home = std::getenv("XDG_CONFIG_HOME"); // NOLINT const string& configDir = cfg_home != nullptr ? cfg_home : "~/.config"; basedir = configDir + "/stella"; homedir = "~/"; diff --git a/src/os/windows/FSNodeWINDOWS.cxx b/src/os/windows/FSNodeWINDOWS.cxx index ef251da01..e9b0eb701 100644 --- a/src/os/windows/FSNodeWINDOWS.cxx +++ b/src/os/windows/FSNodeWINDOWS.cxx @@ -77,7 +77,7 @@ string FSNodeWINDOWS::getShortPath() const if (home != "" && BSPF::startsWithIgnoreCase(_path, home)) { string path = "~"; - const char* offset = _path.c_str() + home.length(); + const char* const offset = _path.c_str() + home.length(); if (*offset != FSNode::PATH_SEPARATOR) path += FSNode::PATH_SEPARATOR; path += offset; @@ -105,13 +105,13 @@ AbstractFSNodePtr FSNodeWINDOWS::getParent() const if (_path.size() > 3) { - const char* start = _path.c_str(); - const char* end = lastPathComponent(_path); + const char* const start = _path.c_str(); + const char* const end = lastPathComponent(_path); - return make_shared(string(start, static_cast(end - start))); + return make_unique(string(start, static_cast(end - start))); } else - return make_shared(); + return make_unique(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -135,7 +135,7 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const entry._isFile = false; entry._isPseudoRoot = false; entry._path = current_drive; - myList.emplace_back(make_shared(entry)); + myList.emplace_back(make_unique(entry)); } } else @@ -164,8 +164,8 @@ void FSNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, { const char* const asciiName = find_data.cFileName; - // Skip local directory (.) and parent (..) - if (!strncmp(asciiName, ".", 1) || !strncmp(asciiName, "..", 2)) + // Skip files starting with '.' (we assume empty filesnames never occur) + if (asciiName[0] == '.') return; const bool isDirectory = static_cast(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); @@ -186,7 +186,7 @@ void FSNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, entry._isPseudoRoot = false; entry._size = find_data.nFileSizeHigh * (static_cast(MAXDWORD) + 1) + find_data.nFileSizeLow; - list.emplace_back(make_shared(entry)); + list.emplace_back(make_unique(entry)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -