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

Rule: sprintf-arguments-mismatch #1011

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Conversation

anderseknert
Copy link
Member

Fixes #1009

Fixes #1009

Signed-off-by: Anders Eknert <anders@styra.com>
some fn
ast.function_calls[_][fn].name == "sprintf"

fn.args[1].type == "array" # can only check static arrays, not vars
Copy link
Member

Choose a reason for hiding this comment

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

😱 that's a possibility... sprintf("%s %s %d", input) etc. what a nightmare

# don't match
report contains violation if {
some fn
ast.function_calls[_][fn].name == "sprintf"
Copy link
Member

Choose a reason for hiding this comment

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

This looks expensive. Have you ever tried using an reverse-index here? Like "all locations where function sprintf is used"

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we've mostly paid the cost at this point, as ast.function_calls essentially filters ast.found.refs keeping only function calls, and then providing them in compact format nicer to work with.

But yeah, ast.found.refs is a beast, and as I'm sure you remember, I tried to collect more types in that traversal, and things... broke :P

Copy link
Member

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks!

@anderseknert anderseknert merged commit c9e4a7e into main Aug 27, 2024
3 checks passed
@anderseknert anderseknert deleted the sprintf-argument-mismatch branch August 27, 2024 09:15
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Fixes StyraInc#1009

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule: sprintf-arguments-mismatch
2 participants