-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static Analysis #202
Static Analysis #202
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nitpicks, a few questions about code being deleted.
Src/GameLoader.cpp
Outdated
@@ -587,7 +587,7 @@ void GameLoader::IdentifyGamesInZipArchive( | |||
Region::ptr_t region = v2.second; | |||
if (!region->required) | |||
continue; | |||
for (auto file: region->files) | |||
for (const auto& file: region->files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this "const auto &file". I prefer that style (and it's consistent with elsewhere in the code that I've written).
Src/GameLoader.cpp
Outdated
@@ -757,7 +757,7 @@ bool GameLoader::ComputeRegionSize(uint32_t *region_size, const GameLoader::Regi | |||
// use maximum end_addr = offset + stride * (num_chunks - 1) + chunk_size. | |||
std::vector<uint32_t> end_addr; | |||
bool error = false; | |||
for (auto file: region->files) | |||
for (const auto& file: region->files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
@@ -261,8 +261,7 @@ void CTextureRefs::DeleteAllHashEntries() | |||
for (unsigned i = 0; i < m_hashCapacity; i++) | |||
{ | |||
HashEntry *entry = m_hashEntries[i]; | |||
if (entry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this check isn't needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, nowadays all compilers respect the c++ standard, that says 'In all cases, if ptr is a null pointer, the standard library deallocation functions do nothing.'
Src/Graphics/Render2D.cpp
Outdated
@@ -411,7 +411,7 @@ void CRender2D::AttachVRAM(const uint8_t* vramPtr) | |||
{ | |||
} | |||
|
|||
void CRender2D::AttachDrawBuffers(std::shared_ptr<TileGenBuffer> bottom, std::shared_ptr<TileGenBuffer> top) | |||
void CRender2D::AttachDrawBuffers(const std::shared_ptr<TileGenBuffer>& bottom, const std::shared_ptr<TileGenBuffer>& top) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Move & to align with left of parameter name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change really isn't needed lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess @dukeeeey is right, this is maybe a bit stupid
Src/Graphics/Render2D.h
Outdated
*/ | ||
void AttachDrawBuffers(std::shared_ptr<TileGenBuffer> bottom, std::shared_ptr<TileGenBuffer> top); | ||
void AttachDrawBuffers(const std::shared_ptr<TileGenBuffer>& bottom, const std::shared_ptr<TileGenBuffer>& top); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: &bottom, &top
Src/OSD/Logger.h
Outdated
@@ -183,13 +183,13 @@ class CFileLogger: public CLogger | |||
void DebugLog(const char *fmt, va_list vl); | |||
void InfoLog(const char *fmt, va_list vl); | |||
void ErrorLog(const char *fmt, va_list vl); | |||
CFileLogger(LogLevel level, std::vector<std::string> filenames); | |||
CFileLogger(LogLevel level, std::vector<std::string> filenames, std::vector<FILE *> systemFiles); | |||
CFileLogger(LogLevel level, const std::vector<std::string>& filenames); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
& alignment
Src/OSD/Logger.h
Outdated
CFileLogger(LogLevel level, std::vector<std::string> filenames); | ||
CFileLogger(LogLevel level, std::vector<std::string> filenames, std::vector<FILE *> systemFiles); | ||
CFileLogger(LogLevel level, const std::vector<std::string>& filenames); | ||
CFileLogger(LogLevel level, const std::vector<std::string>& filenames, const std::vector<FILE *>& systemFiles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
& alignment
@@ -479,13 +479,14 @@ void SCSPDSP_Start(_SCSPDSP *DSP) | |||
} | |||
*/ | |||
|
|||
for(int t=0;t<0x10000;++t) | |||
/* for(int t=0;t<0x10000;++t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this loop being commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simply debug code it seems, as it has no effect in practice (only if one would set a breakpoint in there or the like).
@@ -29,19 +29,19 @@ namespace Util | |||
template <typename T> | |||
struct IntegerEncodableAsHex | |||
{ | |||
static const bool value = std::is_integral<T>::value && sizeof(T) >= 2 && sizeof(T) <= 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a long time since I've looked at this template stuff but I thought these ::value and ::type members were required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The analyzer recommended to modernize it, so it should be equivalent.
Src/Util/NewConfig.cpp
Outdated
@@ -238,7 +238,7 @@ namespace Util | |||
if (Exists()) | |||
m_value->Serialize(os); | |||
*os << "\" children={"; | |||
for (auto v: m_children) | |||
for (const auto& v: m_children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto &v:
All should be addressed, thanks! |
@trzy Is this okay like this? |
Looks good. Thank you! |
Another question regarding constructors, do you prefer the 'classic' initialization a la
or via default member initialization directly in the class/member declaration
Nowadays i personally prefer the latter as then its easier to spot if something has been forgotten, and also the order is clear, if there are dependencies. |
I normally use the latter for structs especially if they have no constructor at all, and the former for classes. If all elements are set to zero or null it just kind of needlessly fattens the class header. But this is just personal preference, I don't think there is a right and wrong answer for this. |
Okay, as i'm currently preparing a PR for more class inits, what to do in case if there is currently a mixture? So some members use a), some b). |
If it has a mixture I mean you can refactor if you want but there isn't a strong need for it. As long as the classes are initialised to a known state. Some of the structs used for rendering its preferable for performance that they not be initialised. All members will be written to anyway. |
Absolutely, the 'small' critical ones i will not touch.. |
Addresses mostly harmless things found by static analysis while trying to nail down #178