ci: check for s2n_array_len in loop bounds #4802
Merged
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.
Description of changes:
Whenever I'm writing a test of the form:
I'm always worried that I'm going to do "sizeof" instead of "s2n_array_len". Best case, that would cause the test to iterate over test cases that don't exist, probably failing, at a minimum probably accessing invalid memory. But worst case, the test silently doesn't execute some test cases. I've made this mistake before.
So I added a grep_simple_mistakes that only allows sizeof in loops for variables with names indicating that's probably safe. I'd love to try to expand it to all uses of sizeof, but that's a MUCH larger set of mistakes. Loops are also what I'm most concerned about: it's a common pattern, and it's very hard to detect the mistake. Other sizeofs are generally used in assertions.
Testing:
Tests continue to pass. Here's an example of a violation:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.