-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixed some static analysis warnings #8762
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
Conversation
That merge commit doesn't belong there. Use |
delete slur; | ||
legatos[slur->track()] = 0; |
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.
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(); |
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.
Not sure we really want to change third party code?
Although new
is used in this file just a few lines below...
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.
You're right; it looks like upstream has fixed this; are there any plans to merge it?
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'm not aware of any such plans.
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'm not aware of any such plans.
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.
Alright, I've reverted that and created a new issue merging upstream at #8808.
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.
Ah, I see, even better
src/engraving/libmscore/lyrics.h
Outdated
@@ -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; } |
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.
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.
Got it, although wouldn't _no & 1
give the same results as _no % 2
? Godbolt seems to show the same assembly generated for both.
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.
_no & 1
is 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; |
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.
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
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.
#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)
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.
See #8849
if (!startSegment) { | ||
return nullptr; | ||
} | ||
|
||
startSegment->measure()->firstEnabled(); |
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.
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; | |||
|
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 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
.
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.
Good point. Since there's a lot of branching here, would a RAII-based solution make more sense than adding this line everywhere?
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.
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.
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.
My terminology might be strange, but I've written up my idea and pushed it to here.
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
1c5cf15
to
29514ba
Compare
13f2857
to
d374119
Compare
d374119
to
ae4ba94
Compare
38bba33
to
c7e325f
Compare
@@ -4392,6 +4405,7 @@ bool OvscParse::parse() | |||
Block placeHolder; | |||
|
|||
m_handle = &handle; | |||
auto _ = ResetToNull(&m_handle); |
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.
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
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.
Interesting... it looks like MinGW doesn't like class template argument deduction for some reason.
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.
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.
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.
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.
Regardless, I do think there's no reason to break anything for this, so I've written in a fix.
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 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); |
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 like my <typeof(*m_handle)>
better
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.
Would it be better to add a free function so the template-deduction happens regardless of version?
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.
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.
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 hoops were lukewarm at best, so I added it—I think it looks a lot nicer.
partial backport of musescore#8762
@@ -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 |
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 seems that this function is used only for debugging. I believe we should just remove it completely because it does more harm than good
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, 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); |
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 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
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.
doesn't seem to be an easy or small change
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
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
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
partial backport of musescore#8762
rebase needed |
partial backport of musescore#8762
closing due to a long period of inactivity |
@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? |
partial backport of musescore#8762
Partially resolves: #8547
Fixes some of the bugs brought up in this article.
Bugs fixed: