@@ -111,17 +111,18 @@ class ConfigValue {
111111 }
112112 catch (const std::invalid_argument&) {
113113 // probably can't occur, but we handle it anyway
114- if (errmsg) *errmsg = " Invalid number format (not numeric)" ;
114+ set_error (errmsg, " Invalid number format (not numeric)" ) ;
115115 return false ;
116116 }
117117 catch (const std::out_of_range&) {
118- if (errmsg) *errmsg = " Number out of range" ;
118+ // the value is out of range, we can not handle it
119+ set_error (errmsg, " Number out of range" );
119120 return false ;
120121 }
121122 catch (...) {
122123 // we don't need to handle all exceptions, the engine's BISON parser
123124 // does not allow other symbols than numbers
124- if (errmsg) *errmsg = " An unknown error occurred while parsed the value." ;
125+ set_error (errmsg, " An unknown error occurred while parsed the value." ) ;
125126 return false ;
126127 }
127128
@@ -135,7 +136,7 @@ class ConfigValue {
135136 (val > static_cast <unsigned long long >(maxValue ()))
136137
137138 ) {
138- if (errmsg) *errmsg = " Value is too big." ;
139+ set_error (errmsg, " Value is too big." ) ;
139140 return false ;
140141 }
141142
@@ -149,7 +150,7 @@ class ConfigValue {
149150 ||
150151 (val < static_cast <unsigned long long >(minValue ()))
151152 ) {
152- if (errmsg) *errmsg = " Value is too small." ;
153+ set_error (errmsg, " Value is too small." ) ;
153154 return false ;
154155 }
155156 }
@@ -161,7 +162,7 @@ class ConfigValue {
161162 ||
162163 (val < static_cast <long long >(minValue ()))
163164 ) {
164- if (errmsg) *errmsg = " Value is too small." ;
165+ set_error (errmsg, " Value is too small." ) ;
165166 return false ;
166167 }
167168 }
@@ -178,6 +179,11 @@ class ConfigValue {
178179 virtual T maxValue () const = 0;
179180 // minValue is optional
180181 virtual T minValue () const { return 0 ; }
182+
183+ private:
184+ static inline void set_error (std::string* err, const char * msg) {
185+ if (err) *err = msg;
186+ }
181187};
182188
183189/* * @ingroup ModSecurity_CPP_API */
0 commit comments