git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 03/18] grep: submodule-related case statements should die if new fields are added

From
Jeff King <peff@peff.net>
Date
Apr 20, 2017, 22:27 UTC
Message-ID
<20170420222747.ooo5z63tzi6d5ayl@sigill.intra.peff.net>
In-Reply-To
<20170420222016.GJ142567@google.com>
On Thu, Apr 20, 2017 at 03:20:16PM -0700, Brandon Williams wrote:
Show 20 quoted lines
> On 04/20, Ævar Arnfjörð Bjarmason wrote:
> > Change two case statements added in commit 0281e487fd ("grep:
> > optionally recurse into submodules", 2016-12-16) so that they die if
> > new GREP_PATTERN_* enum fields are added without updating them.
> > 
> > These case statements currently check for an exhaustive list of
> > fields, but if a new field is added it's easy to introduce a bug here
> > where the code will start subtly doing the wrong thing, e.g. if a new
> > pattern type is added we'll fall through to
> > GREP_PATTERN_TYPE_UNSPECIFIED, i.e. the "basic" POSIX regular
> > expressions.
> > 
> > This should arguably be done for the switch(opt->binary)
> > case-statement as well, but isn't trivial to add since that code isn't
> > currently working with an exhaustive list.
> 
> I was under the impression that the code wouldn't compile if there is a
> missing enum field in the switch statement.  Does it instead silently
> fall through?  I would choose not compiling over a die statement that may
> not be caught during the development of a new series.

Usually -Wswitch would catch this, but the variable in question is declared as an int. The original pattern_type_arg variable is an int because we pass its address via OPT_SET_INT().

We could make the argument to compile_submodule_options() an enum, but then we get an implicit cast when we pass the int (which could fail at runtime). Yech. I'm not sure if there's a good and easy solution.

-Peff
Previous: Brandon WilliamsNext: Ævar Arnfjörð Bjarmason
Message 7 of 22 in “PCRE v1 improvements & PCRE v2 support”
  1. 00/18 PCRE v1 improvements & PCRE v2 supportÆvar Arnfjörð Bjarmason, Apr 20, 2017
  2. 01/18 grep: amend submodule recursion test in preparation for rx engine testingÆvar Arnfjörð Bjarmason, Apr 20, 2017
  3. Brandon WilliamsApr 20, 2017
  4. 02/18 grep: add tests for grep pattern types being passed to submodulesÆvar Arnfjörð Bjarmason, Apr 20, 2017
  5. 03/18 grep: submodule-related case statements should die if new fields are addedÆvar Arnfjörð Bjarmason, Apr 20, 2017
  6. Brandon WilliamsApr 20, 2017
  7. Jeff KingApr 20, 2017
  8. 04/18 grep: remove redundant regflags assignment under PCREÆvar Arnfjörð Bjarmason, Apr 20, 2017
  9. 05/18 Makefile & configure: reword outdated comment about PCREÆvar Arnfjörð Bjarmason, Apr 20, 2017
  10. 06/18 grep: add a test for backreferences in PCRE patternsÆvar Arnfjörð Bjarmason, Apr 20, 2017
  11. 08/18 log: add -P as a synonym for --perl-regexpÆvar Arnfjörð Bjarmason, Apr 20, 2017
  12. 09/18 grep & rev-list doc: stop promising libpcre for --perl-regexpÆvar Arnfjörð Bjarmason, Apr 20, 2017
  13. 10/18 grep: make grep.patternType=[pcre|pcre1] a synonym for "perl"Ævar Arnfjörð Bjarmason, Apr 20, 2017
  14. 11/18 test-lib: rename the LIBPCRE prerequisite to PCREÆvar Arnfjörð Bjarmason, Apr 20, 2017
  15. 12/18 grep: change the internal PCRE macro names to be PCRE1Ævar Arnfjörð Bjarmason, Apr 20, 2017
  16. 13/18 grep: change the internal PCRE code & header names to be PCRE1Ævar Arnfjörð Bjarmason, Apr 20, 2017
  17. 07/18 log: add exhaustive tests for pattern style options & configÆvar Arnfjörð Bjarmason, Apr 20, 2017
  18. 14/18 perf: add a performance comparison test of grep -E and -PÆvar Arnfjörð Bjarmason, Apr 20, 2017
  19. 18/18 Makefile & configure: make PCRE v2 the default PCRE implementationÆvar Arnfjörð Bjarmason, Apr 20, 2017
  20. 16/18 grep: add support for PCRE v2Ævar Arnfjörð Bjarmason, Apr 20, 2017
  21. 17/18 grep: remove support concurrent use of both PCRE v1 & v2Ævar Arnfjörð Bjarmason, Apr 20, 2017
  22. 15/18 grep: add support for the PCRE v1 JIT APIÆvar Arnfjörð Bjarmason, Apr 20, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.