Skip to content
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

Merged
merged 3 commits into from
Oct 5, 2024
Merged

Static Analysis #202

merged 3 commits into from
Oct 5, 2024

Conversation

toxieainc
Copy link
Contributor

Addresses mostly harmless things found by static analysis while trying to nail down #178

Copy link
Owner

@trzy trzy left a 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.

@@ -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)
Copy link
Owner

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).

@@ -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)
Copy link
Owner

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)
Copy link
Owner

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?

Copy link
Contributor Author

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.'

@@ -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)
Copy link
Owner

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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

*/
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);
Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

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)
Copy link
Owner

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?

Copy link
Contributor Author

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;
Copy link
Owner

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?

Copy link
Contributor Author

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.

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto &v:

@toxieainc
Copy link
Contributor Author

All should be addressed, thanks!

@toxieainc
Copy link
Contributor Author

@trzy Is this okay like this?

@trzy trzy merged commit f573681 into trzy:master Oct 5, 2024
@trzy
Copy link
Owner

trzy commented Oct 5, 2024

Looks good. Thank you!

@toxieainc
Copy link
Contributor Author

Another question regarding constructors, do you prefer the 'classic' initialization a la

Bla::Bla() : m_member1(0), m_member2(nullptr), ... ...
{
   memset(...);
   ...
}

or via default member initialization directly in the class/member declaration

class Bla
{
   uint m_member1 = 0;
   void* m_member2 = nullptr;
   ...
}

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.

@dukeeeey
Copy link
Collaborator

dukeeeey commented Oct 5, 2024

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.

@toxieainc
Copy link
Contributor Author

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).

@toxieainc toxieainc deleted the analysis_fixes branch October 5, 2024 17:24
@dukeeeey
Copy link
Collaborator

dukeeeey commented Oct 5, 2024

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.

@toxieainc
Copy link
Contributor Author

Absolutely, the 'small' critical ones i will not touch..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants