grep: remove overly paranoid BUG(...) code

Remove code that would trigger if pcre_config() or pcre2_config() was so broken that "do we have JIT?" wouldn't return a boolean. I added this code back in fbaceaac47 ("grep: add support for the PCRE v1 JIT API", 2017-05-25) and then as noted in f002532784 ("grep: print the pcre2_jit_on value", 2019-07-22) incorrectly copy/pasted some of it in 94da9193a6 ("grep: add support for PCRE v2", 2017-06-01). Let's just remove this code. Being this paranoid about the pcre2?_config() function itself being broken is crossing the line into unreasonable paranoia. Reported-by: Beat Bolli <dev+git@drbeat.li> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 26, 2019 at 17:08 UTC 04bef50c0175bba195443ea0edbf2991175cdd91
1 file changed +2 -8
grep.c
+2 -8
@@ -394,14 +394,11 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
394
395 #ifdef GIT_PCRE1_USE_JIT
396 pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
397 - if (p->pcre1_jit_on == 1) {
397 + if (p->pcre1_jit_on) {
398 p->pcre1_jit_stack = pcre_jit_stack_alloc(1, 1024 * 1024);
399 if (!p->pcre1_jit_stack)
400 die("Couldn't allocate PCRE JIT stack");
401 pcre_assign_jit_stack(p->pcre1_extra_info, NULL, p->pcre1_jit_stack);
402 - } else if (p->pcre1_jit_on != 0) {
403 - BUG("The pcre1_jit_on variable should be 0 or 1, not %d",
404 - p->pcre1_jit_on);
402 }
403 #endif
404 }
@@ -510,7 +507,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
507 }
508
509 pcre2_config(PCRE2_CONFIG_JIT, &p->pcre2_jit_on);
513 - if (p->pcre2_jit_on == 1) {
510 + if (p->pcre2_jit_on) {
511 jitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);
512 if (jitret)
513 die("Couldn't JIT the PCRE2 pattern '%s', got '%d'\n", p->pattern, jitret);
@@ -545,9 +542,6 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
542 if (!p->pcre2_match_context)
543 die("Couldn't allocate PCRE2 match context");
544 pcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack);
548 - } else if (p->pcre2_jit_on != 0) {
549 - BUG("The pcre2_jit_on variable should be 0 or 1, not %d",
550 - p->pcre1_jit_on);
545 }
546 }
547