-
Notifications
You must be signed in to change notification settings - Fork 160
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
Fix crash when comparing recursive data structures #1151
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1151 +/- ##
==========================================
- Coverage 59.27% 59.24% -0.03%
==========================================
Files 434 435 +1
Lines 231096 231106 +10
==========================================
- Hits 136972 136920 -52
- Misses 94124 94186 +62
Continue to review full report at Codecov.
|
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 would add some tests. There are in my mind two types to add:
- Some tests with some
~
in - Some tests where you just do a bunch of comparision of some nested lists and records in a loop of 10,000 iterations or so, where the code has to do some recursion, to make sure we are incrementing/decrementing the recursiondepth correctly.
However, the general design is fine.
src/plist.c
Outdated
return 0L; | ||
} | ||
else if ( ! EQ( elmL, elmR ) ) { | ||
if ( (elmL == 0 ) != (elmR == 0) || ! EQ( elmL, elmR ) ) { |
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.
Can I be picky and ask for another pair of brackets here? I should know what the priority order of !=
and ||
is, but I'm afraid I can't remember. However, I agree the rearranged code is fine.
} | ||
|
||
} | ||
|
||
/* the records are equal or the right is a prefix of the left */ | ||
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.
Pop TLS RecusionDepth?
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.
Absolutely. This is one place where I'd love we were in C++ and could manage this via RAII
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.
(Note that you commented the old version of the code, not the new, hence the fix does not show up here)
938ca61
to
5ededb1
Compare
@ChrisJefferson I am not quite sure I understand what you want to do with your second test... But I suggest you add it yourself once this PR has been merged? |
@fingolfin Will do. Apart from that, I'm now happy with the PR. |
This fixes crashes when comparing recursive data structures (see #1150). With this PR, we get these errors (instead of crashes):
and
etc. etc.
Note that the user can still choose to continue the recursion, and doing so often enough will still crash. That seems acceptable to me, but if desired, we could also produce a variant of this code which prevents the user from returning here.
Also, we should add test cases for these (former) crashes.
Finally, I wonder if other function share similar problems? E.g. are there lists/record types which are not plists / precords and which can also be recursive?