Fix fcase() segfault#6452
Fix fcase() segfault#6452MichaelChirico merged 1 commit into09-02-more_descriptive_variable_names_for_fcase_counting_variablesfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite. This stack of pull requests is managed by Graphite. Learn more about stacking. Join @MichaelChirico and the rest of your teammates on |
84e0932 to
49bc983
Compare
4e5a82d to
25896d2
Compare
|
Generated via commit a563ada Download link for the artifact containing the test results: ↓ atime-results.zip Time taken to finish the standard R installation steps: 10 minutes and 59 seconds Time taken to run |
|
What @aitap suggested is a much simpler one-line fix here: Line 238 in 02ced80 - value0 = thens;
+ value0 = PROTECT(thens); nprotect++;Looking again though, it does look wasteful to me that we repeatedly run It makes the code a bit lengthier, but should be more memory-efficient. |
25896d2 to
3cb9108
Compare
|
Are we sure this is the fix? I am surprised that a miscalculated UNPROTECT would not have triggered a stack imbalance warning message. |
there's no missed unprotect -- because thens is REPROTECT'd. I confirmed the examples from the issue which reliably segfault pretty quickly, no longer do so. |
Without an explicit Edit: use |
|
could you test making the input a factor with other attributes too? that will trigger the max # of branches in fcase with a getAttrib call |
|
Really slick idea to get |
3cb9108 to
a563ada
Compare
|
Here's a test with factors that errors for me on R-devel/data.table from Git on Linux and R-4.4.0/data.table-1.16.0 on Windows, all x86_64: It doesn't fail in a more interesting manner because Somehow, without the lists in the outputs, it takes more effort to get this particular |
|
rchk is a static analyzer, it can't catch everything. possibly it doesn't know how to handle PROTECT_WITH_INDEX. |
9e845c4
into
09-02-more_descriptive_variable_names_for_fcase_counting_variables
|
@kalibera you are the main author of rchk right? |
Unfortunately it is not feasible examples like this would be covered. The main challenge for rchk here is, in rchk terminology, that something gets implicitly protected, but later implicitly unprotected. rchk gets the first part, but isn't able to collect enough information to track the second part ( A higher-level explanation could be that rchk is modelling which "variables" are protected, but it is an approximation (often also of how we think about the code, but still an approximation) - in fact R objects on the heap are protected or not. For this abstraction to work better, one should not copy pointers to SEXPs. When that is still needed, one needs to be careful and perhaps could add a comment to the code about why it does not break protection. Otherwise I confirm the reason of the bug in the code discussed above: |


Closes #6448.
@aitap I didn't add any test -- any ideas for what would make sense as a regression test here? Technically this could have been caught by existing tests, under a stricter operating environment.
The test from OP did reliably segfault, but it's harder to turn that into a test for the absence of a segfault -- experimenting, I was getting it to run 1500+ times before segfaulting.