Skip to content

Fix compiler warnings#1507

Merged
summeroff merged 4 commits intostagingfrom
fix-compiler-warnings
Apr 1, 2025
Merged

Fix compiler warnings#1507
summeroff merged 4 commits intostagingfrom
fix-compiler-warnings

Conversation

@mhoyer-streamlabs
Copy link
Copy Markdown
Contributor

Description

Code changes fix compiler warnings, including both build warnings and Intellisense warnings. The majority of changes involve types and adding explicit casting. Other changes include initializing variables, checking for null pointers, and adding flags to ignore deprecation and security warnings. A handful of deprecated function calls were updated.

Motivation and Context

These changes were made so that legitimate warnings do not get lost in a sea of inconsequential warnings.

How Has This Been Tested?

Yarn tests completed successfully.

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • [x ] The code has been tested.
  • [x ] All commit messages are properly formatted and commits squashed where appropriate.
  • [x ] I have included updates to all appropriate documentation.

Fixes for compiler warnings.

The majority were mismatched types and some uninitialized variables. Added flags to suppress some deprecation/security warnings.

Remove commented out line

More compiler warning fixes

Added some Intellisense warnings.
Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->uid = 0;
Copy link
Copy Markdown
Contributor

@sandboxcoder sandboxcoder Mar 18, 2025

Choose a reason for hiding this comment

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

Just curious why not initialize the variable in the constructor like so:

osn::AudioTrack::AudioTrack(const Napi::CallbackInfo &info) : Napi::ObjectWrap<osn::AudioTrack>(info), uid(0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Old habits die hard...just fell back on how I used to do it.

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->uid = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would initialize the variable in the constructor like so (unless there is some reason not to?):

osn::AudioEncoder::AudioEncoder(const Napi::CallbackInfo &info) : Napi::ObjectWrap<osn::AudioEncoder>(info), uid(0)

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->uid = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I leave this up to you I would init this one in the constructor.

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->moduleId = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking best to define in constructor?

#pragma warning(push, 0)
#include <node.h>
#pragma warning(pop)
//#include <node.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we want to remove this or does the old deprecated code have value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That actually wasn't intentional, just forgot to go back and delete.

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->uid = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

define in constructor?

#pragma warning(push, 0)
#include <node.h>
#pragma warning(pop)
//#include <node.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did we want to keep the dead code?

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->itemId = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

define in constructor?

Napi::HandleScope scope(env);
int length = info.Length();
size_t length = info.Length();
this->uid = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

define in constructor?


for (size_t j = 0; j < item->magnitude.size(); j++) {
magnitude.Set(j, Napi::Number::New(env, item->magnitude[j]));
magnitude.Set(static_cast<uint32_t>(j), Napi::Number::New(env, item->magnitude[j]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could have made the loop variable a uint32_t to avoid the static_cast but I'm not sure how big of an improvement it would be since the uint32_t will just wrap around if we were to go past UINT32_MAX which can be quite a pain. But I'm assuming this code never goes past that limit.

Example:

for (uint32_t j = 0; j < item->magnitude.size(); j++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point, I just left the size_t as that's what .size() returns and used the cast on the line with the warning.

Copy link
Copy Markdown
Contributor

@sandboxcoder sandboxcoder left a comment

Choose a reason for hiding this comment

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

I left some comments but I think they are all trivial (?) thanks this looks good. Big improvement

@summeroff summeroff merged commit 6987e72 into staging Apr 1, 2025
6 checks passed
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