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

Fixed some static analysis warnings #8762

Closed

Conversation

PatrickNorton
Copy link
Contributor

Partially resolves: #8547

Fixes some of the bugs brought up in this article.
Bugs fixed:

  • V501 (importmidi_simplify.cpp 44)
  • V1063 (lyrics.h 85)
  • V1065 (scorediff.cpp 444)
  • V595 (notationselectionrange.cpp 129)
  • V774 (importgtp-gp6.cpp 2592)
  • V506 (ove.cpp 4391)
  • V630 (IntervalTree.h 70)
  • I signed CLA
  • I made sure the code in the PR follows the coding rules
  • I made sure the code compiles on my machine
  • I made sure there are no unnecessary changes in the code
  • I made sure the title of the PR reflects the core meaning of the issue you are solving
  • I made sure the commit message(s) contain a description and answer the question "Why do those changes fix that particular issue?" or "Why are those changes really necessary as improvements?"
  • I made sure the commit message title starts with "fix #424242:" if there is a related issue
  • I created the test (mtest, vtest, script test) to verify the changes I made

@Jojo-Schmitz
Copy link
Contributor

Jojo-Schmitz commented Aug 1, 2021

That merge commit doesn't belong there. Use git pull --rebase instead (followed by git push --force)
And then the remaining 2 comits should get squashed IMHO

delete slur;
legatos[slur->track()] = 0;
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

Good catch, wonder why this ever worked without crashing?

@@ -67,7 +67,7 @@ class IntervalTree {
center = other.center;
intervals = other.intervals;
if (other.left) {
left = (intervalTree*) malloc(sizeof(intervalTree));
left = new intervalTree();
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

Not sure we really want to change third party code?

Although new is used in this file just a few lines below...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right; it looks like upstream has fixed this; are there any plans to merge it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not aware of any such plans.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not aware of any such plans.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've reverted that and created a new issue merging upstream at #8808.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, even better

@@ -92,7 +92,7 @@ class Lyrics final : public TextBase
QString subtypeName() const override { return QObject::tr("Verse %1").arg(_no + 1); }
void setNo(int n) { _no = n; }
int no() const { return _no; }
bool isEven() const { return _no % 1; }
bool isEven() const { return _no % 2; }
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

What is actually really meant here is _no & 1 (or (_no + 1) % 2 or !(no % 2) , _no is 0 based, so 0 is actually verse 1 and as such odd.

See #7628 (for 3.x, got merged) and #7627 (got closed, so master still needs this fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, although wouldn't _no & 1 give the same results as _no % 2? Godbolt seems to show the same assembly generated for both.

Copy link
Contributor

Choose a reason for hiding this comment

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

_no & 1is used in other places, for the very same purpose. So using it here too is a) consistent and b) the save bet

@@ -62,7 +62,7 @@ bool areDurationsEqual(
sum += ReducedFraction(d.second.fraction()) / d.first;
}

return desiredLen == desiredLen;
return sum == desiredLen;
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

See #7627 (review) where this had come up before, and also #7179 (for 3.x), this change results in failing (actually crashing) mtests (on 3.x at least, which is why that PR is still in Draft).

Seems those tests are not yet enabled for master. Also that code only ever gets hit in a Debug build, so not in any release, nor in a 'normal' local MSVC (RelWithDebInfo) build.

See also https://musescore.org/en/node/314899

Copy link
Contributor

Choose a reason for hiding this comment

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

#7179 has just been merged, if you like integrate that one into your PR, else I'd port it over (it basically removes that stuff)

Copy link
Contributor

Choose a reason for hiding this comment

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

See #8849

if (!startSegment) {
return nullptr;
}

startSegment->measure()->firstEnabled();
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

Outch, another good catch!

Note to self: the only change of this PR that won't apply to 3.x, as far as I can tell, except for the lyrics.h one, which is 3.x already)

@@ -4459,6 +4459,8 @@ bool OvscParse::parse()
}
m_ove->setShowColor(placeHolder.toBoolean());

m_handle = nullptr;

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 1, 2021

Choose a reason for hiding this comment

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

Here you left out the other 3 locations that document mentioned. And there are even more of those, many more, as far as can tell, even a few lines up, all these return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Since there's a lot of branching here, would a RAII-based solution make more sense than adding this line everywhere?

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 5, 2021

Choose a reason for hiding this comment

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

Huh? No idea what a a RAII-based solution might be. What I know is that this change is is not enough, jumping (way) too short.

But if you find a simpler one than you just did (it iis rather big), go ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My terminology might be strange, but I've written up my idea and pushed it to here.

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 1, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 2, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 3, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 3, 2021
@@ -4392,6 +4405,7 @@ bool OvscParse::parse()
Block placeHolder;

m_handle = &handle;
auto _ = ResetToNull(&m_handle);
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 7, 2021

Choose a reason for hiding this comment

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

For some reason I don't get that to compile in QtCreator/MinGW (and on top of the 3.x branch):

...\importexport\ove\ove.cpp:3873: Error: missing template arguments before '(' token
...\importexport\ove\ove.cpp: In member function 'virtual bool OVE::TrackParse::parse()':
...\importexport\ove\ove.cpp:3873:27: error: missing template arguments before '(' token
       auto _ = ResetToNull(&handle_);
                           ^

Changing those calls to auto _ = ResetToNull<typeof(*m_handle)>(&handle_); fixes that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting... it looks like MinGW doesn't like class template argument deduction for some reason.

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 7, 2021

Choose a reason for hiding this comment

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

No wonder, as this is C++17. We're not requiring this anywhere yet, just C++14 (for MSVC), C++11 for Xcode, and gnu++11 for gcc (which includes MinGW), although I checked 3.x only, maybe master is a step ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From here, it looks like C++17 is required for master.

As of 484f8dc, 09Oct2020, Qt 5.15 (and a C++17 capable toolchain) is required for the master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regardless, I do think there's no reason to break anything for this, so I've written in a fix.

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 7, 2021

Choose a reason for hiding this comment

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

I see (and yes, I now remember). Still using typeof might be better

@@ -4405,7 +4405,7 @@ bool OvscParse::parse()
Block placeHolder;

m_handle = &handle;
auto _ = ResetToNull(&m_handle);
auto _ = ResetToNull<StreamHandle>(&m_handle);
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 7, 2021

Choose a reason for hiding this comment

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

I like my <typeof(*m_handle)> better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be better to add a free function so the template-deduction happens regardless of version?

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Aug 7, 2021

Choose a reason for hiding this comment

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

If possible without jumping through burning hoops ;-)

But for master it might not be needed, your original version is just fine, as we're having C++17 there as a fixed requirement.

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 hoops were lukewarm at best, so I added it—I think it looks a lot nicer.

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 7, 2021
@@ -62,6 +62,8 @@ bool areDurationsEqual(
sum += ReducedFraction(d.second.fraction()) / d.first;
}

// Note: This looks really weird, but fixing it seems to break several
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this function is used only for debugging. I believe we should just remove it completely because it does more harm than good

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it is used for debugging only, And there causes issues when fixed to do a usefull comparison.

@@ -4392,6 +4411,7 @@ bool OvscParse::parse()
Block placeHolder;

m_handle = &handle;
auto _ = resetToNull(&m_handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this problem should be solved in another way. Better to remove m_handle and add the handle to arguments of BasicParse::readBuffer and BasicParse::jump:

BasicParse::readBuffer(StreamHandle& handle, Block& placeHolder, int size)
BasicParse::jump(StreamHandle& handle, int offset)

This is more explicit and doesn't cause the invalid pointer problem

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't seem to be an easy or small change

Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 9, 2021
by removing the entire thing, it seems useless, esp. that
`return desiredLen == desiredLen;` and even harmful and
wrong anyway.

Duplicate of musescore#7179, but also part of the backport of musescore#8762
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 10, 2021
by removing the entire thing, it seems useless, esp. that
`return desiredLen == desiredLen;` and even harmful and
wrong anyway.

Duplicate of musescore#7179, but also part of the backport of musescore#8762
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 13, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 13, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 19, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 19, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 30, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 1, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 2, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 9, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 10, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 23, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 26, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 29, 2021
@Jojo-Schmitz
Copy link
Contributor

rebase needed

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request May 12, 2022
@RomanPudashkin
Copy link
Contributor

closing due to a long period of inactivity

@RobFog
Copy link

RobFog commented Dec 20, 2022

@PatrickNorton, perhaps, if you're interested, the parts of this pull request that did not receive requests for modification could be submitted in a new pull request?

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 5, 2023
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.

[MU4 Task] [TECH_DEBTS] Static analyzer warnings
4 participants