Fixed numerous compiler warnings reported by the -Wall and -Wpedantic flags.

This commit is contained in:
Leon Styhre 2021-09-19 14:37:10 +02:00
parent c7d815a125
commit 63767347f2
32 changed files with 78 additions and 68 deletions

View file

@ -223,7 +223,7 @@ const std::string FileData::getMediafilePath(std::string subdirectory, std::stri
subFolders + "/" + getDisplayName();
// Look for an image file in the media directory.
for (int i = 0; i < extList.size(); i++) {
for (size_t i = 0; i < extList.size(); i++) {
std::string mediaPath = tempPath + extList[i];
if (Utils::FileSystem::exists(mediaPath))
return mediaPath;
@ -298,7 +298,7 @@ const std::string FileData::getVideoPath() const
getMediaDirectory() + mSystemName + "/videos" + subFolders + "/" + getDisplayName();
// Look for media in the media directory.
for (int i = 0; i < extList.size(); i++) {
for (size_t i = 0; i < extList.size(); i++) {
std::string mediaPath = tempPath + extList[i];
if (Utils::FileSystem::exists(mediaPath))
return mediaPath;

View file

@ -115,8 +115,6 @@ private:
std::vector<std::string> mCompletedIndexFilteredKeys;
std::vector<std::string> mBrokenIndexFilteredKeys;
std::vector<std::string> mHiddenIndexFilteredKeys;
FileData* mRootFolder;
};
#endif // ES_APP_FILE_FILTER_INDEX_H

View file

@ -184,7 +184,7 @@ void MediaViewer::findMedia()
void MediaViewer::showNext()
{
if (mHasImages && mCurrentImageIndex != mImageFiles.size() - 1)
if (mHasImages && mCurrentImageIndex != static_cast<int>(mImageFiles.size()) - 1)
NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND);
bool showedVideo = false;
@ -205,7 +205,7 @@ void MediaViewer::showNext()
if ((mVideo || showedVideo) && !mDisplayingImage)
mCurrentImageIndex = 0;
else if (mImageFiles.size() > mCurrentImageIndex + 1)
else if (static_cast<int>(mImageFiles.size()) > mCurrentImageIndex + 1)
mCurrentImageIndex++;
if (mVideo)
@ -281,7 +281,7 @@ void MediaViewer::showImage(int index)
mDisplayingImage = true;
if (!mImageFiles.empty() && mImageFiles.size() >= index) {
if (!mImageFiles.empty() && static_cast<int>(mImageFiles.size()) >= index) {
mImage = new ImageComponent(mWindow, false, false);
mImage->setImage(mImageFiles[index]);
mImage->setOrigin(0.5f, 0.5f);

View file

@ -283,7 +283,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st
CollectionSystemsManager::get()->deleteCustomCollection(name);
return true;
},
"NO", [this] { return false; }));
"NO", [] { return false; }));
};
row.makeAcceptInputHandler(deleteCollectionCall);
auto customCollection = std::make_shared<TextComponent>(

View file

@ -1331,7 +1331,7 @@ void GuiMenu::close(bool closeAllWindows)
}
else {
Window* window = mWindow;
closeFunc = [window, this] {
closeFunc = [window] {
while (window->peekGui() != ViewController::get())
delete window->peekGui();
};

View file

@ -91,7 +91,8 @@ GuiScraperMenu::GuiScraperMenu(Window* window, std::string title)
}
// The filter setting is only retained during the program session i.e. it's not saved
// to es_settings.xml.
if (mFilters->getSelectedId() != Settings::getInstance()->getInt("ScraperFilter"))
if (mFilters->getSelectedId() !=
static_cast<unsigned int>(Settings::getInstance()->getInt("ScraperFilter")))
Settings::getInstance()->setInt("ScraperFilter", mFilters->getSelectedId());
});

View file

@ -471,7 +471,7 @@ void GuiScraperSearch::updateInfoPane()
if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT && mScraperResults.size())
i = 0;
if (i != -1 && static_cast<int>(mScraperResults.size() > i)) {
if (i != -1 && static_cast<int>(mScraperResults.size()) > i) {
ScraperSearchResult& res = mScraperResults.at(i);
mResultName->setText(Utils::String::toUpper(res.mdl.get("name")));

View file

@ -443,7 +443,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
// Find how many more requests we can make before the scraper
// request allowance counter is reset.
if (doc.HasMember("remaining_monthly_allowance") && doc.HasMember("extra_allowance")) {
for (auto i = 0; i < results.size(); i++) {
for (size_t i = 0; i < results.size(); i++) {
results[i].scraperRequestAllowance =
doc["remaining_monthly_allowance"].GetInt() + doc["extra_allowance"].GetInt();
}

View file

@ -327,7 +327,7 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
mFuncs.push_back(ResolvePair(downloadMediaAsync(it->fileURL, filePath,
it->existingMediaFile, it->subDirectory,
it->resizeFile, mResult.savedNewMedia),
[this, filePath] {}));
[filePath] {}));
}
}
}

View file

@ -181,8 +181,6 @@ void SystemView::goToSystem(SystemData* system, bool animate)
bool SystemView::input(InputConfig* config, Input input)
{
auto it = SystemData::sSystemVector.cbegin();
if (input.value != 0) {
if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_r &&
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {

View file

@ -490,9 +490,11 @@ void GridGameListView::updateInfoPanel()
// An animation is not playing, then animate if opacity != our target opacity.
if ((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) ||
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255))) {
auto func = [comp](float t) {
// TEMPORARY - This does not seem to work, needs to be reviewed later.
// comp->setOpacity(static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
// TEMPORARY - This does not seem to work, needs to be reviewed later.
// auto func = [comp](float t) {
auto func = [](float t) {
// comp->setOpacity(static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
};
comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut);
}

View file

@ -147,6 +147,9 @@ CECInput::CECInput()
mlibCEC = nullptr;
return;
}
#else
// This is simply to get rid of a Clang -Wunused-private-field compiler warning.
mlibCEC = nullptr;
#endif // HAVE_LIBCEC
}

View file

@ -218,13 +218,13 @@ void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData
"Theme set does not include navigation sound support, using fallback sounds";
}
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "systembrowse")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "quicksysselect")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "select")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "back")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "scroll")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "favorite")));
navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "launch")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowse"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "quicksysselect"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "select"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "back"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "scroll"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "favorite"));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "launch"));
}
void NavigationSounds::playThemeNavigationSound(NavigationSoundsID soundID)

View file

@ -14,6 +14,7 @@
#include "utils/FileSystemUtil.h"
#include "utils/MathUtil.h"
#include <any>
#include <deque>
#include <map>
#include <memory>
@ -127,17 +128,17 @@ public:
template <typename T> const T get(const std::string& prop) const
{
if (std::is_same<T, glm::vec2>::value)
return *(const T*)&properties.at(prop).v;
return std::any_cast<const T>(properties.at(prop).v);
else if (std::is_same<T, std::string>::value)
return *(const T*)&properties.at(prop).s;
return std::any_cast<const T>(properties.at(prop).s);
else if (std::is_same<T, unsigned int>::value)
return *(const T*)&properties.at(prop).i;
return std::any_cast<const T>(properties.at(prop).i);
else if (std::is_same<T, float>::value)
return *(const T*)&properties.at(prop).f;
return std::any_cast<const T>(properties.at(prop).f);
else if (std::is_same<T, bool>::value)
return *(const T*)&properties.at(prop).b;
return std::any_cast<const T>(properties.at(prop).b);
else if (std::is_same<T, glm::vec4>::value)
return *(const T*)&properties.at(prop).r;
return std::any_cast<const T>(properties.at(prop).r);
return T();
}

View file

@ -51,6 +51,7 @@ Window::Window()
{
mHelp = new HelpComponent(this);
mBackgroundOverlay = new ImageComponent(this);
mBackgroundOverlayOpacity = 0;
}
Window::~Window()
@ -663,7 +664,7 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
"lt",
"start",
"back"};
int i = 0;
size_t i = 0;
int aVal = 0;
int bVal = 0;
while (i < map.size()) {

View file

@ -190,7 +190,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
// Draw our entries.
std::vector<GuiComponent*> drawAfterCursor;
bool drawAll;
for (unsigned int i = 0; i < mEntries.size(); i++) {
for (size_t i = 0; i < mEntries.size(); i++) {
auto& entry = mEntries.at(i);
drawAll = !mFocused || i != static_cast<unsigned int>(mCursor);
for (auto it = entry.data.elements.cbegin(); it != entry.data.elements.cend(); it++) {
@ -198,7 +198,8 @@ void ComponentList::render(const glm::mat4& parentTrans)
// For the row where the cursor is at, we want to remove any hue from the
// font or image before inverting, as it would otherwise lead to an ugly
// inverted color (e.g. red inverting to a green hue).
if (mFocused && i == mCursor && it->component->getValue() != "") {
if (mFocused && i == static_cast<size_t>(mCursor) &&
it->component->getValue() != "") {
// Check if we're dealing with text or an image component.
bool isTextComponent = true;
unsigned int origColor = it->component->getColor();

View file

@ -137,7 +137,7 @@ public:
const UserData& getNext() const
{
// If there is a next entry, then return it, otherwise return the current entry.
if (mCursor + 1 < mEntries.size())
if (mCursor + 1 < static_cast<int>(mEntries.size()))
return mEntries.at(mCursor + 1).object;
else
return mEntries.at(mCursor).object;

View file

@ -77,7 +77,7 @@ void ImageComponent::resize()
// This will be mTargetSize.x. We can't exceed it, nor be lower than it.
mSize.x *= resizeScale.x;
// We need to make sure we're not creating an image larger than max size.
mSize.y = std::min(floorf(mSize.y *= resizeScale.x), mTargetSize.y);
mSize.y = std::min(floorf(mSize.y * resizeScale.x), mTargetSize.y);
}
else {
// This will be mTargetSize.y(). We can't exceed it.

View file

@ -394,7 +394,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
bool direction = mCursor >= mLastCursor;
int diff = direction ? mCursor - mLastCursor : mLastCursor - mCursor;
if (isScrollLoop() && diff == mEntries.size() - 1)
if (isScrollLoop() && diff == static_cast<int>(mEntries.size()) - 1)
direction = !direction;
int oldStart = mStartPosition;
@ -426,18 +426,18 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
std::shared_ptr<GridTileComponent> newTile = nullptr;
int oldIdx = mLastCursor - mStartPosition + (dimOpposite * EXTRAITEMS);
if (oldIdx >= 0 && oldIdx < mTiles.size())
if (oldIdx >= 0 && oldIdx < static_cast<int>(mTiles.size()))
oldTile = mTiles[oldIdx];
int newIdx = mCursor - mStartPosition + (dimOpposite * EXTRAITEMS);
if (isScrollLoop()) {
if (newIdx < 0)
newIdx += static_cast<int>(mEntries.size());
else if (newIdx >= mTiles.size())
else if (newIdx >= static_cast<int>(mTiles.size()))
newIdx -= static_cast<int>(mEntries.size());
}
if (newIdx >= 0 && newIdx < mTiles.size())
if (newIdx >= 0 && newIdx < static_cast<int>(mTiles.size()))
newTile = mTiles[newIdx];
for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
@ -670,7 +670,7 @@ void ImageGridComponent<T>::updateTileAtPos(int tilePos,
int dif = mCursor - tilePos;
int idx = mLastCursor - dif;
if (idx < 0 || idx >= mTiles.size())
if (idx < 0 || idx >= static_cast<int>(mTiles.size()))
idx = 0;
glm::vec3 pos{mTiles.at(idx)->getBackgroundPosition()};
@ -720,8 +720,10 @@ template <typename T> bool ImageGridComponent<T>::isScrollLoop()
if (!mScrollLoop)
return false;
if (isVertical())
return (mGridDimension.x * (mGridDimension.y - 2 * EXTRAITEMS)) <= mEntries.size();
return (mGridDimension.y * (mGridDimension.x - 2 * EXTRAITEMS)) <= mEntries.size();
return (mGridDimension.x * (mGridDimension.y - 2 * EXTRAITEMS)) <=
static_cast<int>(mEntries.size());
return (mGridDimension.y * (mGridDimension.x - 2 * EXTRAITEMS)) <=
static_cast<int>(mEntries.size());
}
#endif // ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H

View file

@ -183,7 +183,7 @@ bool TextEditComponent::input(InputConfig* config, Input input)
break;
}
case SDLK_DELETE: {
if (mCursor < mText.length()) {
if (mCursor < static_cast<int>(mText.length())) {
// Fake as Backspace one char to the right.
moveCursor(1);
textInput("\b");
@ -245,7 +245,7 @@ void TextEditComponent::onTextChanged()
mFont->buildTextCache(wrappedText, 0.0f, 0.0f, 0x77777700 | getOpacity()));
if (mCursor > static_cast<int>(mText.length()))
mCursor = static_cast<unsigned int>(mText.length());
mCursor = static_cast<int>(mText.length());
}
void TextEditComponent::onCursorChanged()

View file

@ -60,7 +60,7 @@ private:
std::string mTextOrig;
bool mFocused;
bool mEditing;
unsigned int mCursor; // Cursor position in characters.
int mCursor; // Cursor position in characters.
int mBlinkTime;
int mCursorRepeatTimer;

View file

@ -529,8 +529,9 @@ void VideoFFmpegComponent::readFrames()
return;
if (mVideoCodecContext && mFormatContext) {
if (mVideoFrameQueue.size() < mVideoTargetQueueSize ||
(mAudioStreamIndex >= 0 && mAudioFrameQueue.size() < mAudioTargetQueueSize)) {
if (static_cast<int>(mVideoFrameQueue.size()) < mVideoTargetQueueSize ||
(mAudioStreamIndex >= 0 &&
static_cast<int>(mAudioFrameQueue.size()) < mAudioTargetQueueSize)) {
while ((readFrameReturn = av_read_frame(mFormatContext, mPacket)) >= 0) {
if (mPacket->stream_index == mVideoStreamIndex) {
if (!avcodec_send_packet(mVideoCodecContext, mPacket) &&

View file

@ -180,8 +180,8 @@ GuiInputConfig::GuiInputConfig(Window* window,
delete this;
};
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "OK", "ok",
[this, okFunction] { okFunction(); }));
buttons.push_back(
std::make_shared<ButtonComponent>(mWindow, "OK", "ok", [okFunction] { okFunction(); }));
mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtonGrid, glm::ivec2{0, 6}, true, false);

View file

@ -68,7 +68,6 @@ private:
Input mHeldInput;
int mHeldTime;
int mHeldInputId;
bool mSkipAxis;
};
#endif // ES_CORE_GUIS_GUI_INPUT_CONFIG_H

View file

@ -104,7 +104,6 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
, mDeleteRepeat{false}
, mShift{false}
, mAlt{false}
, mAltShift{false}
, mDeleteRepeatTimer{0}
, mNavigationRepeatTimer{0}
, mNavigationRepeatDirX{0}

View file

@ -100,7 +100,6 @@ private:
bool mDeleteRepeat;
bool mShift;
bool mAlt;
bool mAltShift;
int mHorizontalKeyCount;
int mDeleteRepeatTimer;

View file

@ -25,6 +25,7 @@ namespace Renderer
{
static std::stack<Rect> clipStack;
static SDL_Window* sdlWindow = nullptr;
static glm::mat4 mProjectionMatrix;
static int windowWidth = 0;
static int windowHeight = 0;
static int screenWidth = 0;

View file

@ -48,13 +48,15 @@ namespace Renderer
static std::vector<Shader*> sShaderProgramVector;
static GLuint shaderFBO;
static glm::mat4 mProjectionMatrix;
// This is simply to get rid of a GCC false positive -Wunused-variable compiler warning.
static GLuint shaderFBODummy = shaderFBO;
static constexpr glm::mat4 getIdentity() { return glm::mat4{1.0f}; }
#if !defined(NDEBUG)
#define GL_CHECK_ERROR(Function) (Function, _GLCheckError(#Function))
static void _GLCheckError(const std::string& _funcName)
static inline void _GLCheckError(const std::string& _funcName)
{
const GLenum errorCode = glGetError();
@ -162,7 +164,7 @@ namespace Renderer
const Renderer::shaderParameters& parameters = shaderParameters(),
unsigned char* textureRGBA = nullptr);
static unsigned int getWindowFlags() { return SDL_WINDOW_OPENGL; }
static inline unsigned int getWindowFlags() { return SDL_WINDOW_OPENGL; }
void setupWindow();
bool createContext();

View file

@ -456,7 +456,7 @@ namespace Renderer
GL_CHECK_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0));
for (int i = 0; i < shaderList.size(); i++) {
for (size_t i = 0; i < shaderList.size(); i++) {
vertices[0].shaders = shaderList[i];
int shaderPasses = 1;
// For the blur shaders there is an optional variable to set the number of passes

View file

@ -560,17 +560,19 @@ float Font::getNewlineStartOffset(const std::string& text,
case ALIGN_CENTER: {
int endChar = 0;
endChar = static_cast<int>(text.find('\n', charStart));
return (xLen - sizeText(text.substr(charStart, endChar != std::string::npos ?
endChar - charStart :
endChar))
return (xLen - sizeText(text.substr(charStart,
static_cast<size_t>(endChar) != std::string::npos ?
endChar - charStart :
endChar))
.x) /
2.0f;
}
case ALIGN_RIGHT: {
int endChar = static_cast<int>(text.find('\n', charStart));
return xLen - (sizeText(text.substr(charStart, endChar != std::string::npos ?
endChar - charStart :
endChar))
return xLen - (sizeText(text.substr(charStart,
static_cast<size_t>(endChar) != std::string::npos ?
endChar - charStart :
endChar))
.x);
}
default:

View file

@ -18,7 +18,7 @@ namespace Utils
DateTime::DateTime()
{
mTime = 0;
mTimeStruct = {0, 0, 0, 1, 0, 0, 0, 0, -1};
mTimeStruct = {0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0};
mIsoString = "00000000T000000";
}
@ -83,7 +83,7 @@ namespace Utils
{
const char* s = string.c_str();
const char* f = format.c_str();
tm timeStruct = {0, 0, 0, 1, 0, 0, 0, 0, -1};
tm timeStruct = {0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0};
size_t parsedChars = 0;
if (string == "19700101T010000")
@ -231,7 +231,7 @@ namespace Utils
int daysInMonth(const int year, const int month)
{
tm timeStruct = {0, 0, 0, 0, month, year - 1900, 0, 0, -1};
tm timeStruct = {0, 0, 0, 0, month, year - 1900, 0, 0, -1, 0, 0};
mktime(&timeStruct);
return timeStruct.tm_mday;
@ -239,7 +239,7 @@ namespace Utils
int daysInYear(const int year)
{
tm timeStruct = {0, 0, 0, 0, 0, year - 1900 + 1, 0, 0, -1};
tm timeStruct = {0, 0, 0, 0, 0, year - 1900 + 1, 0, 0, -1, 0, 0};
mktime(&timeStruct);
return timeStruct.tm_yday + 1;

View file

@ -20,7 +20,7 @@ namespace Utils
{
namespace Time
{
static int DEFAULT_TIMEVALUE = 0;
constexpr static int DEFAULT_TIMEVALUE = 0;
class DateTime
{