-
Notifications
You must be signed in to change notification settings - Fork 166
invariant_boolean: When searching for references reassignment include PostfixExpression and similar, e.g. variable++. #412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,3 +237,56 @@ void bug372(bool foo) { | |
// doSomethingElse(); | ||
} | ||
} | ||
|
||
void bug337_1(int offset, int length) { | ||
if (offset >= length) { | ||
return; | ||
} | ||
|
||
offset++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to introduce other variables so that you can check other operators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very good idea, but I am not sure which ones to check, can you please provide a few examples? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bwilkerson : thoughts on what @alexeieleusis should check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks the postfix increment operator, but the rule checks for all four combinations of (prefix | postfix) (increment | decrement) operators. There are three operators that are not being tested, and I think they should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I was confused, somehow I thought this was the rule's code. Will add those cases to the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
if (offset >= length) { // OK | ||
} | ||
} | ||
|
||
void bug337_2(int offset, int length) { | ||
if (offset >= length) { | ||
return; | ||
} | ||
|
||
offset--; | ||
if (offset >= length) { // OK | ||
} | ||
} | ||
|
||
void bug337_3(int offset, int length) { | ||
if (offset >= length) { | ||
return; | ||
} | ||
|
||
++offset; | ||
if (offset >= length) { // OK | ||
} | ||
} | ||
|
||
void bug337_4(int offset, int length) { | ||
if (offset >= length) { | ||
return; | ||
} | ||
|
||
--offset; | ||
if (offset >= length) { // OK | ||
} | ||
} | ||
|
||
void test337_5() { | ||
int b = 2; | ||
if (b > 0) { | ||
b--; | ||
if (b == 0) { | ||
return; | ||
} | ||
if (b > 0) { | ||
return; | ||
} | ||
} | ||
} |
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 is fairly inefficient because you have to perform multiple
is
checks for every node, even when you've already determined that it isn't necessary. Perhaps re-structure slightly: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.
Fixed
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.
@bwilkerson: take another look?