-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[silgenpattern] Fix some stack-use-after-free errors caused by iterat…
…ing over an Optional<ArrayRef<T>>. Specifically the bad pattern was: ``` for (auto *vd : *caseStmt->getCaseBodyVariables()) { ... } ``` The problem is that the optional is not lifetime extended over the for loop. To work around this, I changed the API of CaseStmt's getCaseBodyVariable methods to never return the inner Optional<MutableArrayRef<T>>. Now we have the following 3 methods (ignoring const differences): 1. CaseStmt::hasCaseBodyVariables(). 2. CaseStmt::getCaseBodyVariables(). Asserts if the case body variable array was never specified. 3. CaseStmt::getCaseBodyVariablesOrEmptyArray(). Returns either the case body variables array or an empty array if we were never given any case body variable array. This should prevent anyone else in the future from hitting this type of bug. radar://49609717
- Loading branch information
Showing
6 changed files
with
35 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters