2121
2222#include " src/operators/operator.h"
2323
24- #ifndef WITH_PCRE2
24+ #ifdef WITH_PCRE
2525#if PCRE_HAVE_JIT
2626#define pcre_study_opt PCRE_STUDY_JIT_COMPILE
2727#else
28- # define pcre_study_opt 0
28+ constexpr int pcre_study_opt = 0 ;
2929#endif
3030#endif
3131
@@ -34,20 +34,20 @@ namespace modsecurity {
3434namespace operators {
3535
3636VerifyCC::~VerifyCC () {
37- #if WITH_PCRE2
37+ #ifndef WITH_PCRE
3838 pcre2_code_free (m_pc);
3939#else
40- if (m_pc != NULL ) {
40+ if (m_pc != nullptr ) {
4141 pcre_free (m_pc);
42- m_pc = NULL ;
42+ m_pc = nullptr ;
4343 }
44- if (m_pce != NULL ) {
44+ if (m_pce != nullptr ) {
4545#if PCRE_HAVE_JIT
4646 pcre_free_study (m_pce);
4747#else
4848 pcre_free (m_pce);
4949#endif
50- m_pce = NULL ;
50+ m_pce = nullptr ;
5151 }
5252#endif
5353}
@@ -94,33 +94,33 @@ int VerifyCC::luhnVerify(const char *ccnumber, int len) {
9494
9595
9696bool VerifyCC::init (const std::string ¶m2, std::string *error) {
97- #ifdef WITH_PCRE2
97+ #ifndef WITH_PCRE
9898 PCRE2_SPTR pcre2_pattern = reinterpret_cast <PCRE2_SPTR>(m_param.c_str ());
9999 uint32_t pcre2_options = (PCRE2_DOTALL|PCRE2_MULTILINE);
100100 int errornumber = 0 ;
101101 PCRE2_SIZE erroroffset = 0 ;
102102 m_pc = pcre2_compile (pcre2_pattern, PCRE2_ZERO_TERMINATED,
103- pcre2_options, &errornumber, &erroroffset, NULL );
104- if (m_pc == NULL ) {
103+ pcre2_options, &errornumber, &erroroffset, nullptr );
104+ if (m_pc == nullptr ) {
105105 return false ;
106106 }
107107 m_pcje = pcre2_jit_compile (m_pc, PCRE2_JIT_COMPLETE);
108108#else
109- const char *errptr = NULL ;
109+ const char *errptr = nullptr ;
110110 int erroffset = 0 ;
111111
112112 m_pc = pcre_compile (m_param.c_str (), PCRE_DOTALL|PCRE_MULTILINE,
113- &errptr, &erroffset, NULL );
114- if (m_pc == NULL ) {
113+ &errptr, &erroffset, nullptr );
114+ if (m_pc == nullptr ) {
115115 error->assign (errptr);
116116 return false ;
117117 }
118118
119119 m_pce = pcre_study (m_pc, pcre_study_opt, &errptr);
120- if (m_pce == NULL ) {
121- if (errptr == NULL ) {
120+ if (m_pce == nullptr ) {
121+ if (errptr == nullptr ) {
122122 /*
123- * Per pcre_study(3) m_pce == NULL && errptr == NULL means
123+ * Per pcre_study(3) m_pce == nullptr && errptr == nullptr means
124124 * that no addional information is found, so no need to study
125125 */
126126 return true ;
@@ -136,21 +136,21 @@ bool VerifyCC::init(const std::string ¶m2, std::string *error) {
136136
137137bool VerifyCC::evaluate (Transaction *t, RuleWithActions *rule,
138138 const std::string& i, RuleMessage &ruleMessage) {
139- #ifdef WITH_PCRE2
139+ #ifndef WITH_PCRE
140140 PCRE2_SIZE offset = 0 ;
141141 size_t target_length = i.length ();
142142 PCRE2_SPTR pcre2_i = reinterpret_cast <PCRE2_SPTR>(i.c_str ());
143- pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
143+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, nullptr );
144144
145145 int ret;
146146 for (offset = 0 ; offset < target_length; offset++) {
147147
148148 if (m_pcje == 0 ) {
149- ret = pcre2_jit_match (m_pc, pcre2_i, target_length, offset, 0 , match_data, NULL );
149+ ret = pcre2_jit_match (m_pc, pcre2_i, target_length, offset, 0 , match_data, nullptr );
150150 }
151151
152152 if (m_pcje != 0 || ret == PCRE2_ERROR_JIT_STACKLIMIT) {
153- ret = pcre2_match (m_pc, pcre2_i, target_length, offset, PCRE2_NO_JIT, match_data, NULL );
153+ ret = pcre2_match (m_pc, pcre2_i, target_length, offset, PCRE2_NO_JIT, match_data, nullptr );
154154 }
155155
156156 /* If there was no match, then we are done. */
@@ -192,15 +192,15 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
192192 " \" at " + i + " . [offset " +
193193 std::to_string (offset) + " ]" );
194194 }
195- #ifdef WITH_PCRE2
195+ #ifndef WITH_PCRE
196196 pcre2_match_data_free (match_data);
197197#endif
198198 return true ;
199199 }
200200 }
201201 }
202202
203- #ifdef WITH_PCRE2
203+ #ifndef WITH_PCRE
204204 pcre2_match_data_free (match_data);
205205#endif
206206
0 commit comments