This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 sure if this should compile. Later in the function, we have
[comp]. I.e.,compis copied to the heap. Usually, that's not allowed forscopevariables.Uh oh!
There was an error while loading. Please reload this page.
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 assume it works here because the array is assigned to a
scopeparameter and hence promoted to the stack.Uh oh!
There was an error while loading. Please reload this page.
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
[comp]is passed to parameterconst scope string[] valBofcombine, so the literal is allocated on the stackEdit: that's what Florian said, didn't see his message when I posted
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.
That might be DMD's reasoning. But it's unsound. It actually doesn't matter if the array is on the heap or on the stack. A
scopeis being lost.comp.ptris ascopepointer.valB.ptris also ascopepointer.valB[0].ptris not ascopepointer, becausescopeis not transitive. SovalB = [comp];cannot be allowed. It's assigning ascopepointer to a non-scopepointer.Reduced code demonstrating memory corruption:
Uh oh!
There was an error while loading. Please reload this page.
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.
Fair enough, that's just another oddity of
scopenot being transitive.But there's no corruption here because
combinedoesn't escape the string. So it should be fine to wrap the call in a@trustedlambda to avoid future problems.EDIT: The current solution is even 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.
I put the operator in the middle argument of
combine, side-stepping the issue.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.
Btw nice catch @aG0aep6G! I think the relevant bugzilla issue is this:
https://issues.dlang.org/show_bug.cgi?id=20505