Skip to content

Commit 374166c

Browse files
avargitster
authored andcommitted
grep: catch a missing enum in switch statement
Add a die(...) to a default case for the switch statement selecting between grep pattern types under --recurse-submodules. Normally this would be caught by -Wswitch, but the grep_pattern_type type is converted to int by going through parse_options(). Changing the argument type passed to compile_submodule_options() won't work, the value will just get coerced. The -Wswitch-default warning will warn about it, but that produces a lot of noise across the codebase, this potential issue would be drowned in that noise. Thus catching this at runtime is the least bad option. This won't ever trigger in practice, but if a new pattern type were to be added this catches an otherwise silent bug during development. See commit 0281e48 ("grep: optionally recurse into submodules", 2016-12-16) for the initial addition of this code. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 723fc5a commit 374166c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ static void compile_submodule_options(const struct grep_opt *opt,
495495
break;
496496
case GREP_PATTERN_TYPE_UNSPECIFIED:
497497
break;
498+
default:
499+
die("BUG: Added a new grep pattern type without updating switch statement");
498500
}
499501

500502
for (pattern = opt->pattern_list; pattern != NULL;

0 commit comments

Comments
 (0)