diff options
Diffstat (limited to 'src/sp_pcre_compat.c')
| -rw-r--r-- | src/sp_pcre_compat.c | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 203fb7a..81c51fd 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c | |||
| @@ -1,13 +1,5 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | inline void sp_pcre_free(sp_pcre* regexp) { | ||
| 4 | #ifdef SP_HAS_PCRE2 | ||
| 5 | pcre2_code_free(regexp); | ||
| 6 | regexp = NULL; | ||
| 7 | #else | ||
| 8 | (void)regexp; | ||
| 9 | #endif | ||
| 10 | } | ||
| 11 | 3 | ||
| 12 | sp_pcre* sp_pcre_compile(const char* const pattern) { | 4 | sp_pcre* sp_pcre_compile(const char* const pattern) { |
| 13 | assert(NULL != pattern); | 5 | assert(NULL != pattern); |
| @@ -17,9 +9,8 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { | |||
| 17 | unsigned char pcre_error[128] = {0}; | 9 | unsigned char pcre_error[128] = {0}; |
| 18 | int errornumber; | 10 | int errornumber; |
| 19 | PCRE2_SIZE erroroffset; | 11 | PCRE2_SIZE erroroffset; |
| 20 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, | 12 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errornumber, &erroroffset, NULL); |
| 21 | PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | 13 | pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)-1); |
| 22 | pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)); | ||
| 23 | #else | 14 | #else |
| 24 | const char* pcre_error = NULL; | 15 | const char* pcre_error = NULL; |
| 25 | int erroroffset; | 16 | int erroroffset; |
| @@ -27,29 +18,26 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { | |||
| 27 | #endif | 18 | #endif |
| 28 | 19 | ||
| 29 | if (NULL == ret) { | 20 | if (NULL == ret) { |
| 30 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, | 21 | sp_log_err("config", "Failed to compile '%s': %s.", pattern, pcre_error); |
| 31 | pcre_error, sp_line_no); | ||
| 32 | } | 22 | } |
| 33 | return ret; | 23 | return ret; |
| 34 | } | 24 | } |
| 35 | 25 | ||
| 36 | bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, | 26 | bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len) { |
| 37 | size_t len) { | ||
| 38 | int ret = 0; | 27 | int ret = 0; |
| 39 | 28 | ||
| 40 | assert(NULL != regexp); | 29 | assert(NULL != regexp); |
| 41 | assert(NULL != str); | 30 | assert(NULL != str); |
| 42 | 31 | ||
| 43 | #ifdef SP_HAS_PCRE2 | 32 | #ifdef SP_HAS_PCRE2 |
| 44 | pcre2_match_data* match_data = | 33 | pcre2_match_data* match_data = pcre2_match_data_create_from_pattern(regexp, NULL); |
| 45 | pcre2_match_data_create_from_pattern(regexp, NULL); | ||
| 46 | if (NULL == match_data) { | 34 | if (NULL == match_data) { |
| 47 | sp_log_err("regexp", "Unable to get memory for a regxp."); | 35 | sp_log_err("regexp", "Unable to get memory for a regxp."); |
| 48 | } | 36 | } |
| 49 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | 37 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); |
| 50 | pcre2_match_data_free(match_data); | 38 | pcre2_match_data_free(match_data); |
| 51 | #else | 39 | #else |
| 52 | int vec[30]; | 40 | int vec[30] = {0}; |
| 53 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); | 41 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); |
| 54 | #endif | 42 | #endif |
| 55 | 43 | ||
