Fixes from clang-tidy-19 that didn't make it for the last release.

This commit is contained in:
Stephen Anthony 2024-10-06 20:27:25 -02:30
parent 18db75df5e
commit 2d184b6754
37 changed files with 185 additions and 246 deletions

View File

@ -381,8 +381,7 @@ string HighScoresManager::formattedScore(Int32 score, Int32 width) const
if(scoreBCD(jprops))
{
if(width > digits)
digits = width;
digits = std::max(width, digits);
buf << std::setw(digits) << std::setfill(' ') << score;
}
else {

View File

@ -188,8 +188,7 @@ json JoyMap::saveMapping(EventMode mode) const
using MapType = std::pair<JoyMapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());
std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
std::ranges::sort(sortedMap, [](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.first.button != b.first.button)
@ -285,17 +284,17 @@ int JoyMap::loadMapping(const json& eventMappings, EventMode mode)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
json JoyMap::convertLegacyMapping(string list)
json JoyMap::convertLegacyMapping(string lst)
{
json eventMappings = json::array();
// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
std::replace(list.begin(), list.end(), '|', ' ');
std::replace(list.begin(), list.end(), ':', ' ');
std::replace(list.begin(), list.end(), ',', ' ');
std::ranges::replace(lst, '|', ' ');
std::ranges::replace(lst, ':', ' ');
std::ranges::replace(lst, ',', ' ');
istringstream buf(list);
istringstream buf(lst);
int event = 0, button = 0, axis = 0, adir = 0, hat = 0, hdir = 0;
while(buf >> event && buf >> button

View File

@ -112,7 +112,7 @@ class JoyMap
nlohmann::json saveMapping(EventMode mode) const;
int loadMapping(const nlohmann::json& eventMappings, EventMode mode);
static nlohmann::json convertLegacyMapping(string list);
static nlohmann::json convertLegacyMapping(string lst);
/** Erase all mappings for given mode */
void eraseMode(EventMode mode);

View File

@ -222,8 +222,7 @@ json KeyMap::saveMapping(EventMode mode) const
using MapType = std::pair<Mapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());
std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
std::ranges::sort(sortedMap, [](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.first.key != b.first.key)
@ -290,11 +289,11 @@ json KeyMap::convertLegacyMapping(string_view lm)
// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
string list{lm};
std::replace(list.begin(), list.end(), '|', ' ');
std::replace(list.begin(), list.end(), ':', ' ');
std::replace(list.begin(), list.end(), ',', ' ');
istringstream buf(list);
string lst{lm};
std::ranges::replace(lst, '|', ' ');
std::ranges::replace(lst, ':', ' ');
std::ranges::replace(lst, ',', ' ');
istringstream buf(lst);
int event = 0, key = 0, mod = 0;
while(buf >> event && buf >> key && buf >> mod)

View File

@ -478,9 +478,9 @@ void PaletteHandler::generateCustomPalette(ConsoleTiming timing) const
float G = Y + dotProduct(IQ[chroma], IQG);
float B = Y + dotProduct(IQ[chroma], IQB);
if(R < 0) R = 0;
if(G < 0) G = 0;
if(B < 0) B = 0;
R = std::max(R, 0.F);
G = std::max(G, 0.F);
B = std::max(B, 0.F);
R = powf(R, 0.9F);
G = powf(G, 0.9F);

View File

@ -112,26 +112,26 @@ json PhysicalJoystick::convertLegacyMapping(string_view mapping, string_view nam
{
istringstream buf(string{mapping}); // TODO: fixed in C++23
json convertedMapping = json::object();
string map;
string lmap;
// Skip joystick name
getline(buf, map, MODE_DELIM);
getline(buf, lmap, MODE_DELIM);
while (getline(buf, map, MODE_DELIM))
while (getline(buf, lmap, MODE_DELIM))
{
int mode{0};
// Get event mode
std::replace(map.begin(), map.end(), '|', ' ');
istringstream modeBuf(map);
std::ranges::replace(lmap, '|', ' ');
istringstream modeBuf(lmap);
modeBuf >> mode;
// Remove leading "<mode>|" string
map.erase(0, 2);
lmap.erase(0, 2);
const json mappingForMode = JoyMap::convertLegacyMapping(map);
const json lmappingForMode = JoyMap::convertLegacyMapping(lmap);
convertedMapping[jsonName(static_cast<EventMode>(mode))] = mappingForMode;
convertedMapping[jsonName(static_cast<EventMode>(mode))] = lmappingForMode;
}
convertedMapping["name"] = name;

View File

@ -479,7 +479,7 @@ void SoundSDL2::WavHandlerSDL2::processWav(uInt8* stream, uInt32 len)
const int newFreq =
std::round(static_cast<double>(mySpec.freq) * origLen / len);
if(len > myRemaining)
if(len > myRemaining) // NOLINT(readability-use-std-min-max)
len = myRemaining;
SDL_AudioCVT cvt;
@ -505,7 +505,7 @@ void SoundSDL2::WavHandlerSDL2::processWav(uInt8* stream, uInt32 len)
}
else
{
if(len > myRemaining)
if(len > myRemaining) // NOLINT(readability-use-std-min-max)
len = myRemaining;
// Mix volume adjusted WAV data into silent buffer

View File

@ -18,7 +18,7 @@
#ifndef VERSION_HXX
#define VERSION_HXX
#define STELLA_VERSION "7.0"
#define STELLA_VERSION "7.1_pre"
#define STELLA_BUILD "8005"
#endif

View File

@ -266,8 +266,7 @@ void ZipHandler::ZipFile::readEcd()
uInt64 read_length = 0;
// Max out the buf length at the size of the file
if(buflen > myLength)
buflen = myLength;
buflen = std::min(buflen, myLength);
// Allocate buffer
const ByteBuffer buffer = make_unique<uInt8[]>(buflen + 1);

View File

@ -56,6 +56,7 @@ using uInt64 = uint64_t;
#include <cstdio>
#include <ctime>
#include <numbers>
#include <ranges>
#include <utility>
#include <vector>
#include <optional>
@ -189,12 +190,12 @@ namespace BSPF
// Convert string to given case
inline const string& toUpperCase(string& s)
{
transform(s.begin(), s.end(), s.begin(), ::toupper);
std::ranges::transform(s, s.begin(), ::toupper);
return s;
}
inline const string& toLowerCase(string& s)
{
transform(s.begin(), s.end(), s.begin(), ::tolower);
std::ranges::transform(s, s.begin(), ::tolower);
return s;
}
@ -426,9 +427,9 @@ namespace BSPF
const auto currtime = std::time(nullptr);
std::tm tm_snapshot{};
#if (defined BSPF_WINDOWS || defined __WIN32__) && (!defined __GNUG__ || defined __MINGW32__)
localtime_s(&tm_snapshot, &currtime);
std::ignore = localtime_s(&tm_snapshot, &currtime);
#else
localtime_r(&currtime, &tm_snapshot);
std::ignore = localtime_r(&currtime, &tm_snapshot);
#endif
return tm_snapshot;
}

View File

@ -40,6 +40,8 @@
#include "CheatManager.hxx"
#endif
namespace {
/**
Parse the commandline arguments and store into the appropriate hashmap.
@ -47,39 +49,6 @@
Some keys are used only by the main function; these are placed in localOpts.
The rest are needed globally, and are placed in globalOpts.
*/
void parseCommandLine(int ac, const char* const av[],
Settings::Options& globalOpts, Settings::Options& localOpts);
/**
Checks the commandline for special settings that are used by various ports
to use a specific 'base directory'.
This needs to be done separately, before either an OSystem or Settings
object can be created, since they both depend on each other, and a
variable basedir implies a different location for the settings file.
This function will call OSystem::overrideBaseDir() when either of the
applicable arguments are found, and then remove them from the argument
list.
*/
void checkForCustomBaseDir(Settings::Options& options);
/**
Checks whether the commandline contains an argument corresponding to
starting a profile session.
*/
bool isProfilingRun(int ac, char* av[]);
/**
In Windows, attach console to allow command line output (e.g. for -help).
This is needed since by default Windows doesn't set up stdout/stderr
correctly.
*/
void attachConsole();
void freeConsole();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void parseCommandLine(int ac, const char* const av[],
Settings::Options& globalOpts, Settings::Options& localOpts)
{
@ -136,7 +105,18 @@ void parseCommandLine(int ac, const char* const av[],
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
Checks the commandline for special settings that are used by various ports
to use a specific 'base directory'.
This needs to be done separately, before either an OSystem or Settings
object can be created, since they both depend on each other, and a
variable basedir implies a different location for the settings file.
This function will call OSystem::overrideBaseDir() when either of the
applicable arguments are found, and then remove them from the argument
list.
*/
void checkForCustomBaseDir(Settings::Options& options)
{
// If both of these are activated, the 'base in app dir' takes precedence
@ -150,14 +130,22 @@ void checkForCustomBaseDir(Settings::Options& options)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool isProfilingRun(int ac, char* av[]) {
/**
Checks whether the commandline contains an argument corresponding to
starting a profile session.
*/
bool isProfilingRun(int ac, char* av[])
{
if (ac <= 1) return false;
return string(av[1]) == "-profile";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
In Windows, attach console to allow command line output (e.g. for -help).
This is needed since by default Windows doesn't set up stdout/stderr
correctly.
*/
void attachConsole()
{
#if defined(BSPF_WINDOWS)
@ -183,7 +171,6 @@ void attachConsole()
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void freeConsole()
{
#if defined(BSPF_WINDOWS)
@ -192,6 +179,9 @@ void freeConsole()
#endif
}
} // namespace
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#if defined(BSPF_MACOS)
int stellaMain(int ac, char* av[])

View File

@ -28,12 +28,14 @@
template<typename T>
class KeyValueRepositoryFile : public KeyValueRepository {
public:
explicit KeyValueRepositoryFile(const FSNode& node);
KVRMap load() override;
bool save(const KVRMap& values) override;
private:
explicit KeyValueRepositoryFile(const FSNode& node);
friend T;
protected:
const FSNode& myNode; // NOLINT: we want a reference here

View File

@ -19,8 +19,10 @@
#include "NTSCFilter.hxx"
namespace {
constexpr float scaleFrom100(float x) { return (x / 50.F) - 1.F; }
constexpr uInt32 scaleTo100(float x) { return static_cast<uInt32>(50.0001F * (x + 1.F)); }
} // namespace
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string NTSCFilter::setPreset(Preset preset)

View File

@ -793,8 +793,8 @@ bool Debugger::addFunction(string_view name, string_view definition,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Debugger::isBuiltinFunction(string_view name)
{
return std::any_of(ourBuiltinFunctions.cbegin(), ourBuiltinFunctions.cend(),
[&](const auto& func) { return name == func.name; });
return std::ranges::any_of(ourBuiltinFunctions,
[&name](const auto& func) { return name == func.name; });
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -845,10 +845,8 @@ string Debugger::builtinHelp()
// Get column widths for aligned output (functions)
for(const auto& func: ourBuiltinFunctions)
{
size_t len = func.name.size();
if(len > c_maxlen) c_maxlen = len;
len = func.defn.size();
if(len > i_maxlen) i_maxlen = len;
c_maxlen = std::max(func.name.size(), c_maxlen);
i_maxlen = std::max(func.defn.size(), i_maxlen);
}
buf << std::setfill(' ') << "\nBuilt-in functions:\n";
@ -865,10 +863,7 @@ string Debugger::builtinHelp()
// Get column widths for aligned output (pseudo-registers)
c_maxlen = 0;
for(const auto& reg: ourPseudoRegisters)
{
const size_t len = reg.name.size();
if(len > c_maxlen) c_maxlen = len;
}
c_maxlen = std::max(reg.name.size(), c_maxlen);
buf << "\nPseudo-registers:\n";
for(const auto& reg: ourPseudoRegisters)

View File

@ -1481,10 +1481,7 @@ void DebuggerParser::executeHelp()
// Find length of longest command
size_t clen = 0;
for(const auto& c: commands)
{
const size_t len = c.cmdString.length();
if(len > clen) clen = len;
}
clen = std::max(clen, c.cmdString.length());
commandResult << setfill(' ');
for(const auto& c: commands)

View File

@ -69,8 +69,7 @@ int CartDebugWidget::addBaseInformation(size_t bytes, string_view manufacturer,
const StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) /
myFontWidth);
const StringList& sl = bs.stringList();
size_t lines = sl.size();
if(lines < 3) lines = 3;
size_t lines = std::max<size_t>(sl.size(), 3);
bool useScrollbar = false;
if(lines > maxlines)
{

View File

@ -64,10 +64,9 @@ CartRamWidget::CartRamWidget(
constexpr uInt16 maxlines = 6;
const StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) / myFontWidth);
const StringList& sl = bs.stringList();
auto lines = static_cast<uInt32>(sl.size());
bool useScrollbar = false;
if(lines < 2) lines = 2;
bool useScrollbar = false;
auto lines = std::max<uInt32>(static_cast<uInt32>(sl.size()), 2);
if(lines > maxlines)
{
lines = maxlines;

View File

@ -118,10 +118,8 @@ void DataGridWidget::setList(const IntArray& alist, const IntArray& vlist,
const size_t size = vlist.size(); // assume the alist is the same size
const bool dirty = _editMode
|| !std::equal(_valueList.begin(), _valueList.end(),
vlist.begin(), vlist.end())
|| !std::equal(_changedList.begin(), _changedList.end(),
changed.begin(), changed.end());
|| !std::ranges::equal(_valueList, vlist)
|| !std::ranges::equal(_changedList, changed);
_addrList.clear();
_valueList.clear();

View File

@ -170,9 +170,8 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
if(_scrollLine < _currentPos / _lineWidth)
{
// Scroll page by page when not at cursor position:
_scrollLine += _linesPerPage;
if(_scrollLine > _promptEndPos / _lineWidth)
_scrollLine = _promptEndPos / _lineWidth;
_scrollLine = std::min(_scrollLine + _linesPerPage,
_promptEndPos / _lineWidth);
updateScrollBuffer();
break;
}
@ -293,9 +292,8 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
if(_scrollLine < _linesPerPage)
break;
_scrollLine -= _linesPerPage - 1;
if(_scrollLine < _firstLineInBuffer + _linesPerPage - 1)
_scrollLine = _firstLineInBuffer + _linesPerPage - 1;
_scrollLine = std::max(_scrollLine - (_linesPerPage - 1),
_firstLineInBuffer + _linesPerPage - 1);
updateScrollBuffer();
break;
@ -304,9 +302,8 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
if(_scrollLine >= _promptEndPos / _lineWidth)
break;
_scrollLine += _linesPerPage - 1;
if(_scrollLine > _promptEndPos / _lineWidth)
_scrollLine = _promptEndPos / _lineWidth;
_scrollLine = std::min(_scrollLine + (_linesPerPage - 1),
_promptEndPos / _lineWidth);
updateScrollBuffer();
break;
@ -316,9 +313,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
break;
case Event::UIEnd:
_scrollLine = _promptEndPos / _lineWidth;
if(_scrollLine < _linesPerPage - 1)
_scrollLine = _linesPerPage - 1;
_scrollLine = std::max(_promptEndPos / _lineWidth, _linesPerPage - 1);
updateScrollBuffer();
break;
@ -727,8 +722,7 @@ bool PromptWidget::autoComplete(int direction)
if(_tabCount != -1)
len = static_cast<int>(strlen(_inputStr));
if(len > kLineBufferSize - 1)
len = kLineBufferSize - 1;
len = std::min(len, kLineBufferSize - 1);
int lastDelimPos = -1;
char delimiter = '\0';
@ -748,11 +742,11 @@ bool PromptWidget::autoComplete(int direction)
if(_tabCount == -1)
_inputStr[len] = '\0';
StringList list;
StringList lst;
if(lastDelimPos == -1)
// no delimiters, do only command completion:
DebuggerParser::getCompletions(_inputStr, list);
DebuggerParser::getCompletions(_inputStr, lst);
else
{
const size_t strLen = len - lastDelimPos - 1;
@ -761,29 +755,29 @@ bool PromptWidget::autoComplete(int direction)
{
// Special case for 'help' command
if(BSPF::startsWithIgnoreCase(_inputStr, "help"))
DebuggerParser::getCompletions(_inputStr + lastDelimPos + 1, list);
DebuggerParser::getCompletions(_inputStr + lastDelimPos + 1, lst);
else
{
// we got a delimiter, so this must be a label or a function
const Debugger& dbg = instance().debugger();
dbg.cartDebug().getCompletions(_inputStr + lastDelimPos + 1, list);
dbg.getCompletions(_inputStr + lastDelimPos + 1, list);
dbg.cartDebug().getCompletions(_inputStr + lastDelimPos + 1, lst);
dbg.getCompletions(_inputStr + lastDelimPos + 1, lst);
}
}
}
if(list.empty())
if(lst.empty())
return false;
sort(list.begin(), list.end());
std::ranges::sort(lst);
if(direction < 0)
{
if(--_tabCount < 0)
_tabCount = static_cast<int>(list.size()) - 1;
_tabCount = static_cast<int>(lst.size()) - 1;
}
else
_tabCount = (_tabCount + 1) % list.size();
_tabCount = (_tabCount + 1) % lst.size();
nextLine();
_currentPos = _promptStartPos;
@ -796,7 +790,7 @@ bool PromptWidget::autoComplete(int direction)
putcharIntern(delimiter);
// ...and add current autocompletion string
print(list[_tabCount]);
print(lst[_tabCount]);
putcharIntern(' ');
_promptEndPos = _currentPos;

View File

@ -164,11 +164,7 @@ void RomListWidget::setHighlighted(int item)
// Only scroll the list if we're about to pass the page boundary
if (_highlightedItem < _currentPos)
{
_currentPos -= _rows;
if (_currentPos < 0)
_currentPos = 0;
}
_currentPos = std::max(_currentPos - _rows, 0);
else if(_highlightedItem == _currentPos + _rows)
_currentPos += _rows;
@ -187,10 +183,7 @@ void RomListWidget::recalc()
{
const int size = static_cast<int>(myDisasm->list.size());
if (_currentPos >= size)
_currentPos = size - 1;
if (_currentPos < 0)
_currentPos = 0;
_currentPos = BSPF::clamp(_currentPos, 0, size - 1);
if(_selectedItem < 0 || _selectedItem >= size)
_selectedItem = 0;
@ -378,15 +371,12 @@ bool RomListWidget::handleEvent(Event::Type e)
break;
case Event::UIPgUp:
_selectedItem -= _rows - 1;
if (_selectedItem < 0)
_selectedItem = 0;
_selectedItem = std::max(_selectedItem - (_rows - 1), 0);
break;
case Event::UIPgDown:
_selectedItem += _rows - 1;
if (_selectedItem >= static_cast<int>(myDisasm->list.size()))
_selectedItem = static_cast<int>(myDisasm->list.size()) - 1;
_selectedItem = std::min(_selectedItem + (_rows - 1),
static_cast<int>(myDisasm->list.size()) - 1);
break;
case Event::UIHome:

View File

@ -68,8 +68,7 @@ void ToggleBitWidget::setList(const StringList& off, const StringList& on)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ToggleBitWidget::setState(const BoolArray& state, const BoolArray& changed)
{
if(!std::equal(_changedList.begin(), _changedList.end(),
changed.begin(), changed.end()))
if(!std::ranges::equal(_changedList, changed))
setDirty();
_stateList.clear();
@ -78,7 +77,6 @@ void ToggleBitWidget::setState(const BoolArray& state, const BoolArray& changed)
_changedList = changed;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string ToggleBitWidget::getToolTip(const Common::Point& pos) const
{

View File

@ -33,6 +33,8 @@
#include "CartELF.hxx"
// NOLINTBEGIN(bugprone-unchecked-optional-access)
using namespace elfEnvironment;
namespace {
@ -178,7 +180,7 @@ namespace {
{
if (!props) return SystemType::ntsc;
const string displayFormat = props->get(PropType::Display_Format);
const string& displayFormat = props->get(PropType::Display_Format);
if(displayFormat == "PAL" || displayFormat == "SECAM") return SystemType::pal;
if(displayFormat == "PAL60") return SystemType::pal60;
@ -767,3 +769,5 @@ void CartridgeELF::resetWithConfig()
switchExecutionStage();
}
// NOLINTEND(bugprone-unchecked-optional-access)

View File

@ -2051,15 +2051,15 @@ void EventHandler::setComboMap()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
json EventHandler::convertLegacyComboMapping(string list)
json EventHandler::convertLegacyComboMapping(string lst)
{
json convertedMapping = json::array();
// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
std::replace(list.begin(), list.end(), ':', ' ');
std::replace(list.begin(), list.end(), ',', ' ');
istringstream buf(list);
std::ranges::replace(lst, ':', ' ');
std::ranges::replace(lst, ',', ' ');
istringstream buf(lst);
try
{

View File

@ -475,7 +475,7 @@ class EventHandler
void setActionMappings(EventMode mode);
void setDefaultKeymap(Event::Type, EventMode mode);
void setDefaultJoymap(Event::Type, EventMode mode);
static nlohmann::json convertLegacyComboMapping(string list);
static nlohmann::json convertLegacyComboMapping(string lst);
void saveComboMapping();
static StringList getActionList(EventMode mode);

View File

@ -89,8 +89,7 @@ bool FSNode::getAllChildren(FSList& fslist, ListMode mode,
}
#endif
std::sort(fslist.begin(), fslist.end(),
[](const FSNode& node1, const FSNode& node2)
std::ranges::sort(fslist, [](const FSNode& node1, const FSNode& node2)
{
if(node1.isDirectory() != node2.isDirectory())
return node1.isDirectory();
@ -153,7 +152,7 @@ bool FSNode::getChildren(FSList& fslist, ListMode mode,
}
#endif
std::sort(tmp.begin(), tmp.end(),
std::ranges::sort(tmp,
[](const AbstractFSNodePtr& node1, const AbstractFSNodePtr& node2)
{
if(node1->isDirectory() != node2->isDirectory())

View File

@ -478,7 +478,7 @@ void PlusROM::receive()
// and start over
const auto [responseSize, response] = (*iter)->getResponse();
for(uInt8 i = 0; i < responseSize; i++)
for(size_t i = 0; i < responseSize; ++i)
myRxBuffer[myRxWritePos++] = response[i];
myPendingRequests.erase(iter);

View File

@ -366,7 +366,7 @@ void Settings::validate()
if(i < -5 || i > 5) setValue("tia.vsizeadjust", 0);
string s = getString("tia.dbgcolors");
sort(s.begin(), s.end());
std::ranges::sort(s);
if(s != "bgopry") setValue("tia.dbgcolors", "roygpb");
if(PhosphorHandler::toPhosphorMode(getString(PhosphorHandler::SETTING_MODE)) == PhosphorHandler::ByRom)

View File

@ -181,7 +181,7 @@ void VcsLib::vcsWrite5(uInt8 zpAddress, uInt8 value)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VcsLib::vcsCopyOverblankToRiotRam()
{
for (uInt8 i = 0; i < OVERBLANK_PROGRAM_SIZE; i++)
for (uInt32 i = 0; i < OVERBLANK_PROGRAM_SIZE; ++i)
vcsWrite5(0x80 + i, OVERBLANK_PROGRAM[i]);
}

View File

@ -987,9 +987,8 @@ void Dialog::addOKBGroup(WidgetArray& wid, const GUI::Font& font,
VBORDER = Dialog::vBorder(),
HBORDER = Dialog::hBorder();
buttonWidth = std::max(buttonWidth,
std::max(Dialog::buttonWidth(okText),
Dialog::buttonWidth("Cancel")));
buttonWidth = std::max({buttonWidth, Dialog::buttonWidth(okText),
Dialog::buttonWidth("Cancel")});
_w = std::max(HBORDER * 2 + buttonWidth * 2 + BUTTON_GAP, _w);
addOKWidget(new ButtonWidget(this, font, (_w - buttonWidth) / 2,
@ -1007,10 +1006,10 @@ void Dialog::addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font,
VBORDER = Dialog::vBorder(),
HBORDER = Dialog::hBorder();
buttonWidth = std::max(buttonWidth,
std::max(Dialog::buttonWidth("Defaults"),
std::max(Dialog::buttonWidth(okText),
Dialog::buttonWidth(cancelText))));
buttonWidth = std::max({buttonWidth,
Dialog::buttonWidth("Defaults"),
Dialog::buttonWidth(okText),
Dialog::buttonWidth(cancelText)});
_w = std::max(HBORDER * 2 + buttonWidth * 2 + BUTTON_GAP, _w);

View File

@ -64,9 +64,8 @@ void EditableWidget::setText(string_view str, bool changed)
_caretPos = static_cast<int>(_editString.size());
_selectSize = 0;
_editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().w()));
if (_editScrollOffset < 0)
_editScrollOffset = 0;
_editScrollOffset = std::max<int>(0,
_font.getStringWidth(_editString) - getEditRect().w());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -424,8 +423,8 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
if(handled)
{
// Put caret at last difference
myUndoHandler->lastDiff(_editString, oldString);
setCaretPos(myUndoHandler->lastDiff(_editString, oldString));
UndoHandler::lastDiff(_editString, oldString);
setCaretPos(UndoHandler::lastDiff(_editString, oldString));
_selectSize = 0;
sendCommand(EditableWidget::kChangedCmd, key, _id);
}
@ -583,9 +582,7 @@ bool EditableWidget::adjustOffset()
if (strWidth - _editScrollOffset < editWidth)
{
// scroll right
_editScrollOffset = (strWidth - editWidth);
if (_editScrollOffset < 0)
_editScrollOffset = 0;
_editScrollOffset = std::max(strWidth - editWidth, 0);
}
}

View File

@ -182,8 +182,7 @@ const FavoritesManager::UserList& FavoritesManager::userList() const
sortedList.assign(myUserSet.begin(), myUserSet.end());
if(!mySettings.getBool("altsorting"))
std::sort(sortedList.begin(), sortedList.end(),
[](string_view a, string_view b)
std::ranges::sort(sortedList, [](string_view a, string_view b)
{
// Sort without path
const FSNode aNode(a);
@ -221,7 +220,7 @@ void FavoritesManager::addRecent(string_view path)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FavoritesManager::removeRecent(string_view path)
{
auto it = std::find(myRecentList.begin(), myRecentList.end(), path);
auto it = std::ranges::find(myRecentList, path);
if(it != myRecentList.end())
myRecentList.erase(it);
@ -246,8 +245,7 @@ const FavoritesManager::RecentList& FavoritesManager::recentList() const
{
sortedList.assign(myRecentList.begin(), myRecentList.end());
std::sort(sortedList.begin(), sortedList.end(),
[](string_view a, string_view b)
std::ranges::sort(sortedList, [](string_view a, string_view b)
{
// Sort alphabetical, without path
const FSNode aNode(a);
@ -324,8 +322,7 @@ FavoritesManager::sortedPopularList(bool sortByName) const
sortedList.clear();
sortedList.assign(myPopularMap.begin(), myPopularMap.end());
std::sort(sortedList.begin(), sortedList.end(),
[sortByName](const PopularType& a, const PopularType& b)
std::ranges::sort(sortedList, [sortByName](const PopularType& a, const PopularType& b)
{
// 1. sort by most popular
if(!sortByName && a.second != b.second)

View File

@ -141,17 +141,14 @@ void ListWidget::setHighlighted(int item)
const string& ListWidget::getSelectedString() const
{
return (_selectedItem >= 0 && _selectedItem < static_cast<int>(_list.size()))
? _list[_selectedItem] : EmptyString;
? _list[_selectedItem]
: EmptyString;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ListWidget::scrollTo(int item)
{
const int size = static_cast<int>(_list.size());
if (item >= size)
item = size - 1;
if (item < 0)
item = 0;
item = BSPF::clamp(item, 0, static_cast<int>(_list.size() - 1));
if(_currentPos != item)
{
@ -178,14 +175,8 @@ void ListWidget::recalc()
else
_currentPos = size - _rows;
}
if (_currentPos < 0)
_currentPos = 0;
if(_selectedItem >= size)
_selectedItem = size - 1;
if(_selectedItem < 0)
_selectedItem = 0;
_currentPos = std::max(_currentPos, 0);
_selectedItem = BSPF::clamp(_selectedItem, 0, size - 1);
_editMode = false;
if(_useScrollbar)
@ -351,16 +342,12 @@ bool ListWidget::handleEvent(Event::Type e)
case Event::UIPgUp:
case Event::UILeft:
_selectedItem -= _rows - 1;
if (_selectedItem < 0)
_selectedItem = 0;
_selectedItem = std::max(_selectedItem - (_rows - 1), 0);
break;
case Event::UIPgDown:
case Event::UIRight:
_selectedItem += _rows - 1;
if (_selectedItem >= size)
_selectedItem = size - 1;
_selectedItem = std::min(_selectedItem + (_rows - 1), size - 1);
break;
case Event::UIHome:

View File

@ -244,8 +244,8 @@ bool RomImageWidget::getImageList(const string& propName, const string& romName,
// Sort again, not considering extensions, else <filename.png|jpg> would be at
// the end of the list
std::sort(myImageList.begin(), myImageList.end(),
[oldFileName](const FSNode& node1, const FSNode& node2)
std::ranges::sort(myImageList, [oldFileName]
(const FSNode& node1, const FSNode& node2)
{
const int compare = BSPF::compareIgnoreCase(
node1.getNameWithExt(), node2.getNameWithExt());
@ -395,9 +395,9 @@ void RomImageWidget::zoomSurfaces(bool zoomed, bool force)
const Int32 lh = maxSize.h - b * 2;
const Int32 iw = mySrcRect.w() * scaleDpi;
const Int32 ih = mySrcRect.h() * scaleDpi;
const float zoom = std::min(1.F, // do not zoom beyond original size
std::min(static_cast<float>(lw) / iw,
static_cast<float>(lh) / ih));
const float zoom = std::min({1.F, // do not zoom beyond original size
static_cast<float>(lw) / iw,
static_cast<float>(lh) / ih});
const Int32 w = iw * zoom;
const Int32 h = ih * zoom;

View File

@ -184,15 +184,10 @@ void ScrollBarWidget::handleMouseMoved(int x, int y)
if(_draggingPart == Part::Slider)
{
_sliderPos = BSPF::clamp(y - _sliderDeltaMouseDownPos,
_upDownBoxHeight, _h - _upDownBoxHeight - _sliderHeight);
const int old_pos = _currentPos;
_sliderPos = y - _sliderDeltaMouseDownPos;
if(_sliderPos < _upDownBoxHeight)
_sliderPos = _upDownBoxHeight;
if(_sliderPos > _h - _upDownBoxHeight - _sliderHeight)
_sliderPos = _h - _upDownBoxHeight - _sliderHeight;
_currentPos = (_sliderPos - _upDownBoxHeight) * (_numEntries - _entriesPerPage) /
(_h - 2 * _upDownBoxHeight - _sliderHeight);
checkBounds(old_pos);
@ -256,14 +251,12 @@ void ScrollBarWidget::recalc()
if(_numEntries > _entriesPerPage)
{
_sliderHeight = (_h - 2 * _upDownBoxHeight) * _entriesPerPage / _numEntries;
if(_sliderHeight < _upDownBoxHeight)
_sliderHeight = _upDownBoxHeight;
_sliderHeight = std::max(_upDownBoxHeight,
(_h - 2 * _upDownBoxHeight) * _entriesPerPage / _numEntries);
_sliderPos = _upDownBoxHeight + (_h - 2 * _upDownBoxHeight - _sliderHeight) *
_currentPos / (_numEntries - _entriesPerPage);
if(_sliderPos < 0)
_sliderPos = 0;
_sliderPos = std::max(0,
_upDownBoxHeight + (_h - 2 * _upDownBoxHeight - _sliderHeight) *
_currentPos / (_numEntries - _entriesPerPage));
}
else
{
@ -309,10 +302,9 @@ void ScrollBarWidget::drawWidget(bool hilite)
if(!isSinglePage)
{
// align slider to scroll intervals
int alignedPos = _upDownBoxHeight + (_h - 2 * _upDownBoxHeight - _sliderHeight) *
_currentPos / (_numEntries - _entriesPerPage);
if(alignedPos < 0)
alignedPos = 0;
const int alignedPos = std::max(0,
_upDownBoxHeight + (_h - 2 * _upDownBoxHeight - _sliderHeight) *
_currentPos / (_numEntries - _entriesPerPage));
s.fillRect(_x + 1, _y + alignedPos - 1, _w - 2, _sliderHeight + 2,
(hilite && _part == Part::Slider) ? kScrollColorHi : kScrollColor);

View File

@ -81,14 +81,12 @@ int TabWidget::addTab(string_view title, int tabWidth)
}
if(tabWidth == NO_WIDTH)
if(_tabWidth < newWidth)
_tabWidth = newWidth;
_tabWidth = std::max(_tabWidth, newWidth);
if(numTabs - fixedTabs)
{
const int maxWidth = (_w - kTabLeftOffset - fixedWidth) / (numTabs - fixedTabs) - kTabLeftOffset;
if(_tabWidth > maxWidth)
_tabWidth = maxWidth;
_tabWidth = std::min(_tabWidth, maxWidth);
}
// Activate the new tab

View File

@ -157,7 +157,7 @@ void ToolTip::show(string_view tip)
{
string leftStr, rightStr;
surface()->splitString(*myFont, inStr, maxWidth, leftStr, rightStr);
FBSurface::splitString(*myFont, inStr, maxWidth, leftStr, rightStr);
width = std::max(width, static_cast<uInt32>(myFont->getStringWidth(leftStr)));
inStr = rightStr;
}

View File

@ -1,12 +1,13 @@
#!/usr/bin/env bash
run-clang-tidy-18 -header-filter=\(.*\.hxx\) \
run-clang-tidy-19 -header-filter=\(.*\.hxx\) \
-checks=*,\
-abseil*,\
-altera*,\
-android*,\
-fuchsia*,\
-llvmlibc-inline-function-decl,\
-boost-use-ranges,\
-bugprone-assignment-in-if-condition,\
-bugprone-branch-clone,\
-bugprone-easily-swappable-parameters,\
@ -15,6 +16,7 @@ run-clang-tidy-18 -header-filter=\(.*\.hxx\) \
-cert-dcl37-c,\
-cert-dcl51-cpp,\
-cert-err58-cpp,\
-cert-int09-c,\
-clang-analyzer-cplusplus.NewDeleteLeaks,\
-clang-analyzer-optin.performance.Padding,\
-cppcoreguidelines-avoid-c-arrays,\
@ -60,6 +62,7 @@ run-clang-tidy-18 -header-filter=\(.*\.hxx\) \
-modernize-avoid-bind,\
-modernize-avoid-c-arrays,\
-modernize-pass-by-value,\
-modernize-use-designated-initializers,\
-modernize-use-equals-delete,\
-modernize-use-nodiscard,\
-modernize-use-trailing-return-type,\
@ -67,11 +70,13 @@ run-clang-tidy-18 -header-filter=\(.*\.hxx\) \
-readability-avoid-unconditional-preprocessor-if,\
-readability-braces-around-statements,\
-readability-else-after-return,\
-readability-enum-initial-value,\
-readability-function-cognitive-complexity,\
-readability-identifier-length,\
-readability-implicit-bool-conversion,\
-readability-isolate-declaration,\
-readability-magic-numbers,\
-readability-math-missing-parentheses,\
-readability-named-parameter,\
-readability-redundant-access-specifiers,\
-readability-simplify-boolean-expr,\