From 930bdce57636d7bced1906ca9f6e86989234a850 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 17 Oct 2020 14:05:41 +0200 Subject: [PATCH] Fixed multiple issues reported by the Clang static analyzer. --- INSTALL.md | 15 ++++++++++++--- es-app/src/guis/GuiScraperSearch.cpp | 1 - es-core/src/ThemeData.cpp | 8 +++++--- es-core/src/ThemeData.h | 8 ++++++-- es-core/src/components/VideoComponent.h | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 14b5b10ea..362f8b5cb 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -54,13 +54,13 @@ make ``` Keep in mind though that a debug version will be much slower due to all compiler optimizations being disabled. -To create a profiling build, run this: +To create a profiling build (optimized with debug symbols), run this: ``` cmake -DCMAKE_BUILD_TYPE=Profiling . make ``` -You can then profile the code with valgrind: +You can then profile the code with Valgrind: ``` valgrind --tool=callgrind ./emulationstation ``` @@ -73,7 +73,16 @@ To check for memory leaks, the following command is useful: valgrind --tool=memcheck --leak-check=full ./emulationstation ``` -Note that you can also profile either a normal build or a debug build, but it's recommended to use the profiling build for reasons that is beyond the scope of this document. +Note that you can also profile either a normal build or a debug build, but it's normally recommended to use the profiling build as it's compiled with optimizations while retaining the debug symbols. But if you need to alternate between Valgrind and the normal debugger the optimizations can be very annoying and therefore a normal debug build could be recommended in that instance. + +Another useful tool is **scan-build**, assuming you use Clang/LLVM. This is a static analyzer that runs during compilation to provide a very helpful HTML report of potential bugs (well it should be actual bugs but some false positives could be included). You need to run it for both the cmake and make steps, here's an example: + +``` +scan-build cmake -DCMAKE_BUILD_TYPE=Debug . +scan-build make -j6 +``` + +You open the report with the **scan-view** command which lets you browse it using your web browser. Note that the compilation time is much higher when using the static analyzer compared to a normal compilation. As well this tool generates a lot of extra files and folders in the build tree, so it may make sense to run it on a separate copy of the ES source folder to avoid having to clean up all this extra data when the analysis has been completed. To build ES with CEC support, add the corresponding option, for example: diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 48433e0be..ae8bc1214 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -542,7 +542,6 @@ void GuiScraperSearch::update(int deltaTime) if (mMDRetrieveURLsHandle && mMDRetrieveURLsHandle->status() != ASYNC_IN_PROGRESS) { if (mMDRetrieveURLsHandle->status() == ASYNC_DONE) { - auto status_media = mMDRetrieveURLsHandle->status(); auto results_media = mMDRetrieveURLsHandle->getResults(); auto statusString_media = mMDRetrieveURLsHandle->getStatusString(); auto results_scrape = mScraperResults; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index b678ed647..20a8e244c 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -591,9 +591,11 @@ std::vector ThemeData::makeExtras(const std::shared_ptrsetDefaultZIndex(10); - comp->applyTheme(theme, view, *it, ThemeFlags::ALL); - comps.push_back(comp); + if (comp) { + comp->setDefaultZIndex(10); + comp->applyTheme(theme, view, *it, ThemeFlags::ALL); + comps.push_back(comp); + } } } diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index 472fadcda..9561ec69d 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -102,8 +102,12 @@ public: std::string type; struct Property { - void operator= (const Vector4f& value) { r = value; - v = Vector2f(value.x(), value.y()); } + void operator= (const Vector4f& value) + { + r = value; + const Vector4f initVector = value; + v = Vector2f(initVector.x(), initVector.y()); + } void operator= (const Vector2f& value) { v = value; } void operator= (const std::string& value) { s = value; } void operator= (const unsigned int& value) { i = value; } diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index 37b06d70f..fff9eb4a0 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -86,7 +86,7 @@ public: private: // Start the video immediately. - virtual void startVideo() = 0; + virtual void startVideo() {}; // Stop the video. virtual void stopVideo() {}; // Pause the video when a game has been launched.