Re: [PATCH 1/2] introduce "banned function" list
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Jul 20, 2018, 12:42 UTC
- Message-ID
- <153e7256-cc45-c33e-d64a-27319b42a489@gmail.com>
- In-Reply-To
- <20180719203901.GA8079@sigill.intra.peff.net>
On 7/19/2018 4:39 PM, Jeff King wrote:
Show 24 quoted lines
> There are a few standard C functions (like strcpy) which are > easy to misuse. We generally discourage these in reviews, > but we haven't put advice in CodingGuidelines, nor provided > any automated enforcement. The latter is especially > important because it's more consistent, and it can often > save a round-trip of review. > > Let's start by banning strcpy() and sprintf(). It's not > impossible to use these correctly, but it's easy to do so > incorrectly, and there's always a better option. > > For enforcement, we can rely on the compiler and just > introduce code which breaks compilation when it sees these > functions. This has a few advantages: > > 1. We know it's run as part of a build cycle, so it's > hard to ignore. Whereas an external linter is an extra > step the developer needs to remember to do. > > 2. Likewise, it's basically free since the compiler is > parsing the code anyway. > > 3. We know it's robust against false positives (unlike a > grep-based linter).
I know I'm late to the party, but I just wanted to chime in that I think this is a great idea. The more checks we have as part of the developer cycle means we have fewer checks that need to be caught manually in review (or can be missed in review).
Thanks,
-Stolee