-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
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 |
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'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" |
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.
This looks expensive. Have you ever tried using an reverse-index here? Like "all locations where function sprintf
is used"
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 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
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.
Thanks!
Fixes StyraInc#1009 Signed-off-by: Anders Eknert <anders@styra.com>
Fixes #1009