From 3635121123e086b9092c7118dc0a99cb1736dc25 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 Jan 2023 19:35:08 -0800 Subject: grep: diagnose no UTF-8 support (Bug#60708) * src/pcresearch.c (Pcompile): Issue a diagnostic and exit instead of misbehaving if libpcre2 does not support the requested locale. --- src/pcresearch.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pcresearch.c b/src/pcresearch.c index a8034fbc..5b111bea 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -145,10 +145,12 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact) = pcre2_general_context_create (private_malloc, private_free, NULL); pcre2_compile_context *ccontext = pcre2_compile_context_create (gcontext); - uint32_t unicode = 1; - pcre2_config (PCRE2_CONFIG_UNICODE, &unicode); - if (unicode && localeinfo.multibyte) + if (localeinfo.multibyte) { + uint32_t unicode; + if (pcre2_config (PCRE2_CONFIG_UNICODE, &unicode) < 0 || !unicode) + die (EXIT_TROUBLE, 0, + _("-P supports only unibyte locales on this platform")); if (! localeinfo.using_utf8) die (EXIT_TROUBLE, 0, _("-P supports only unibyte and UTF-8 locales")); flags |= (PCRE2_UTF | PCRE2_UCP); -- cgit v1.2.1