| 293 | } |
| 294 | |
| 295 | static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt) |
| 296 | { |
| 297 | int error; |
| 298 | PCRE2_UCHAR errbuf[256]; |
| 299 | PCRE2_SIZE erroffset; |
| 300 | int options = PCRE2_MULTILINE; |
| 301 | int jitret; |
| 302 | int patinforet; |
| 303 | size_t jitsizearg; |
| 304 | int literal = !opt->ignore_case && (p->fixed || p->is_fixed); |
| 305 | |
| 306 | /* |
| 307 | * Call pcre2_general_context_create() before calling any |
| 308 | * other pcre2_*(). It sets up our malloc()/free() functions |
| 309 | * with which everything else is allocated. |
| 310 | */ |
| 311 | p->pcre2_general_context = pcre2_general_context_create( |
| 312 | pcre2_malloc, pcre2_free, NULL); |
| 313 | if (!p->pcre2_general_context) |
| 314 | die("Couldn't allocate PCRE2 general context"); |
| 315 | |
| 316 | if (opt->ignore_case) { |
| 317 | if (!opt->ignore_locale && has_non_ascii(p->pattern)) { |
| 318 | p->pcre2_tables = pcre2_maketables(p->pcre2_general_context); |
| 319 | p->pcre2_compile_context = pcre2_compile_context_create(p->pcre2_general_context); |
| 320 | pcre2_set_character_tables(p->pcre2_compile_context, |
| 321 | p->pcre2_tables); |
| 322 | } |
| 323 | options |= PCRE2_CASELESS; |
| 324 | } |
| 325 | if (!opt->ignore_locale && is_utf8_locale() && !literal) |
| 326 | options |= (PCRE2_UTF | PCRE2_UCP | PCRE2_MATCH_INVALID_UTF); |
| 327 | |
| 328 | #ifndef GIT_PCRE2_VERSION_10_35_OR_HIGHER |
| 329 | /* |
| 330 | * Work around a JIT bug related to invalid Unicode character handling |
| 331 | * fixed in 10.35: |
| 332 | * https://github.com/PCRE2Project/pcre2/commit/c21bd977547d |
| 333 | */ |
| 334 | options &= ~PCRE2_UCP; |
| 335 | #endif |
| 336 | |
| 337 | #ifndef GIT_PCRE2_VERSION_10_36_OR_HIGHER |
| 338 | /* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */ |
| 339 | if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS)) |
| 340 | options |= PCRE2_NO_START_OPTIMIZE; |
| 341 | #endif |
| 342 | |
| 343 | p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern, |
| 344 | p->patternlen, options, &error, &erroffset, |
| 345 | p->pcre2_compile_context); |
| 346 | |
| 347 | if (p->pcre2_pattern) { |
| 348 | p->pcre2_match_data = pcre2_match_data_create_from_pattern(p->pcre2_pattern, p->pcre2_general_context); |
| 349 | if (!p->pcre2_match_data) |
| 350 | die("Couldn't allocate PCRE2 match data"); |
| 351 | } else { |
| 352 | pcre2_get_error_message(error, errbuf, sizeof(errbuf)); |
no test coverage detected