From 4a298b402413bb15c52588e6d40bdcf26a993270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 20 Jun 2017 13:22:58 +0300 Subject: [PATCH] Return NULL if no regex parameter is defined If no regex type parameters are defined and a compiled pattern is requested, the function will return a NULL value. This allows code that directly calls the config_get_compiled_regex function to work without doing additional checks for the presence of optional parameters. --- server/core/config.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/core/config.cc b/server/core/config.cc index 17fd24048..b191ec263 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -1244,9 +1244,16 @@ pcre2_code* config_get_compiled_regex(const MXS_CONFIG_PARAMETER *params, uint32_t* output_ovec_size) { const char* regex_string = config_get_string(params, key); - uint32_t jit_available = 0; - pcre2_config(PCRE2_CONFIG_JIT, &jit_available); - return compile_regex_string(regex_string, jit_available, options, output_ovec_size); + pcre2_code* code = NULL; + + if (*regex_string) + { + uint32_t jit_available = 0; + pcre2_config(PCRE2_CONFIG_JIT, &jit_available); + code = compile_regex_string(regex_string, jit_available, options, output_ovec_size); + } + + return code; } MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param)