Skip to content
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

Swift: "contentsOf" sources #14879

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Swift: "contentsOf" sources #14879

wants to merge 3 commits into from

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Nov 22, 2023

Adds a simple heuristic matching of "contentsOf" functions as flow sources in Swift code. In practice many of the sources found by this heuristic are already modelled - Data(contentsOfFile:) is especially common. But we now catch some more obscure stuff as well, e.g. NSDictionary(contentsOf:), NSImage(contentsOf:), NSArray(contentsOfFile:) and AVAudioPlayer(contentsOf:)...

@geoffw0 geoffw0 added the Swift label Nov 22, 2023
@geoffw0 geoffw0 requested a review from a team as a code owner November 22, 2023 15:49
Comment on lines +19 to +23
exists(InitializerCallExpr ce, Argument arg |
ce.getAnArgument() = arg and
arg.getLabel() = ["contentsOf", "contentsOfFile", "contentsOfPath", "contentsOfDirectory"] and
arg.getExpr().getType().getUnderlyingType().getName() = ["URL", "NSURL"] and
this.asExpr() = ce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to have a common implementation for this snippet that we can use in InitializerContentsOfLocalSource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, that will improve maintainability...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants