diff options
| author | Christian Göttsche | 2024-06-06 16:36:40 +0200 |
|---|---|---|
| committer | jvoisin | 2024-06-06 16:36:40 +0200 |
| commit | 849252c6a48b428dde3ad8930b40a2bdf9874cb7 (patch) | |
| tree | 0fdc4d1e65c0f4fb4f670b95390c41be808b1ad1 /src/sp_config_scanner.re | |
| parent | 381aa67af284e421ce6554e7bf6039dda5e674b9 (diff) | |
Add format attribute to log function and adjust format specifiers
Annotate the common logging function sp_log_msgf() with the format
attribute so compilers can check the used format string and passed
arguments for discrepancies.
Adjust the lineno printing by using %zu and the type size_t
consistently.
Diffstat (limited to 'src/sp_config_scanner.re')
| -rw-r--r-- | src/sp_config_scanner.re | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index 8f0b24e..f9a6ce9 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re | |||
| @@ -90,11 +90,11 @@ static void str_dtor(zval *zv) { | |||
| 90 | 90 | ||
| 91 | // sy_ functions and macros are helpers for the shunting yard algorithm | 91 | // sy_ functions and macros are helpers for the shunting yard algorithm |
| 92 | #define sy_res_push(val) \ | 92 | #define sy_res_push(val) \ |
| 93 | if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ | 93 | if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ |
| 94 | cond_res[cond_res_i++] = val; | 94 | cond_res[cond_res_i++] = val; |
| 95 | #define sy_res_pop() cond_res[--cond_res_i] | 95 | #define sy_res_pop() cond_res[--cond_res_i] |
| 96 | #define sy_op_push(op) \ | 96 | #define sy_op_push(op) \ |
| 97 | if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ | 97 | if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ |
| 98 | cond_op[cond_op_i++] = op; | 98 | cond_op[cond_op_i++] = op; |
| 99 | #define sy_op_pop() cond_op[--cond_op_i] | 99 | #define sy_op_pop() cond_op[--cond_op_i] |
| 100 | #define sy_op_peek() cond_op[cond_op_i-1] | 100 | #define sy_op_peek() cond_op[cond_op_i-1] |
| @@ -138,7 +138,7 @@ static int sy_apply_op(const char op, const int a, const int b) { | |||
| 138 | #define SY_APPLY_OP_FROM_STACK() \ | 138 | #define SY_APPLY_OP_FROM_STACK() \ |
| 139 | char op = sy_op_pop(); \ | 139 | char op = sy_op_pop(); \ |
| 140 | int unary = (op == '!'); \ | 140 | int unary = (op == '!'); \ |
| 141 | if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %d", lineno); goto out; } \ | 141 | if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %zu", lineno); goto out; } \ |
| 142 | int a = sy_res_pop(); \ | 142 | int a = sy_res_pop(); \ |
| 143 | int b = unary ? 0 : sy_res_pop(); \ | 143 | int b = unary ? 0 : sy_res_pop(); \ |
| 144 | int res = sy_apply_op(op, a, b); \ | 144 | int res = sy_apply_op(op, a, b); \ |
| @@ -169,7 +169,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 169 | int cond_op_i = 0; | 169 | int cond_op_i = 0; |
| 170 | 170 | ||
| 171 | int cond = yycinit; | 171 | int cond = yycinit; |
| 172 | long lineno = 1; | 172 | size_t lineno = 1; |
| 173 | 173 | ||
| 174 | /*!stags:re2c format = 'const char *@@;\n'; */ | 174 | /*!stags:re2c format = 'const char *@@;\n'; */ |
| 175 | /*!re2c | 175 | /*!re2c |
| @@ -189,7 +189,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 189 | keyword = [a-zA-Z][a-zA-Z0-9_]*; | 189 | keyword = [a-zA-Z][a-zA-Z0-9_]*; |
| 190 | string = ["] ("\\"["] | [^"\r\n\x00])* ["]; | 190 | string = ["] ("\\"["] | [^"\r\n\x00])* ["]; |
| 191 | 191 | ||
| 192 | <init> * { cs_log_error("parser error on line %d", lineno); goto out; } | 192 | <init> * { cs_log_error("parser error on line %zu", lineno); goto out; } |
| 193 | <init> whitespace+ { goto yyc_init; } | 193 | <init> whitespace+ { goto yyc_init; } |
| 194 | <init> [;#] [^\r\n\x00]* { goto yyc_init; } | 194 | <init> [;#] [^\r\n\x00]* { goto yyc_init; } |
| 195 | <init> newline { lineno++; goto yyc_init; } | 195 | <init> newline { lineno++; goto yyc_init; } |
| @@ -212,19 +212,19 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 212 | <init> ( "@log" | "@info" ) whitespace+ @t1 string @t2 ";" { | 212 | <init> ( "@log" | "@info" ) whitespace+ @t1 string @t2 ";" { |
| 213 | if (!cond_res[0]) { goto yyc_init; } | 213 | if (!cond_res[0]) { goto yyc_init; } |
| 214 | TMPSTR(tmpstr, t2, t1); | 214 | TMPSTR(tmpstr, t2, t1); |
| 215 | cs_log_info("[line %d]: %s", lineno, tmpstr); | 215 | cs_log_info("[line %zu]: %s", lineno, tmpstr); |
| 216 | goto yyc_init; | 216 | goto yyc_init; |
| 217 | } | 217 | } |
| 218 | <init> ( "@warn" | "@warning" ) whitespace+ @t1 string @t2 ";" { | 218 | <init> ( "@warn" | "@warning" ) whitespace+ @t1 string @t2 ";" { |
| 219 | if (!cond_res[0]) { goto yyc_init; } | 219 | if (!cond_res[0]) { goto yyc_init; } |
| 220 | TMPSTR(tmpstr, t2, t1); | 220 | TMPSTR(tmpstr, t2, t1); |
| 221 | cs_log_warning("[line %d]: %s", lineno, tmpstr); | 221 | cs_log_warning("[line %zu]: %s", lineno, tmpstr); |
| 222 | goto yyc_init; | 222 | goto yyc_init; |
| 223 | } | 223 | } |
| 224 | <init> ( "@err" | "@error" ) whitespace+ @t1 string @t2 ";" { | 224 | <init> ( "@err" | "@error" ) whitespace+ @t1 string @t2 ";" { |
| 225 | if (!cond_res[0]) { goto yyc_init; } | 225 | if (!cond_res[0]) { goto yyc_init; } |
| 226 | TMPSTR(tmpstr, t2, t1); | 226 | TMPSTR(tmpstr, t2, t1); |
| 227 | cs_log_error("[line %d]: %s", lineno, tmpstr); | 227 | cs_log_error("[line %zu]: %s", lineno, tmpstr); |
| 228 | goto out; | 228 | goto out; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| @@ -236,7 +236,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 236 | int is_loaded = (zend_hash_str_find_ptr(&module_registry, t3+1, t4-t3-2) != NULL); | 236 | int is_loaded = (zend_hash_str_find_ptr(&module_registry, t3+1, t4-t3-2) != NULL); |
| 237 | sy_res_push(is_loaded); | 237 | sy_res_push(is_loaded); |
| 238 | } else { | 238 | } else { |
| 239 | cs_log_error("unknown function in condition on line %d", lineno); | 239 | cs_log_error("unknown function in condition on line %zu", lineno); |
| 240 | goto out; | 240 | goto out; |
| 241 | } | 241 | } |
| 242 | goto yyc_cond_op; | 242 | goto yyc_cond_op; |
| @@ -244,7 +244,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 244 | <cond> @t1 keyword @t2 { | 244 | <cond> @t1 keyword @t2 { |
| 245 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t1, t2-t1); | 245 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t1, t2-t1); |
| 246 | if (!tmp) { | 246 | if (!tmp) { |
| 247 | cs_log_error("unknown variable in condition on line %d", lineno); | 247 | cs_log_error("unknown variable in condition on line %zu", lineno); |
| 248 | goto out; | 248 | goto out; |
| 249 | } | 249 | } |
| 250 | sy_res_push(atoi(ZSTR_VAL(tmp))); | 250 | sy_res_push(atoi(ZSTR_VAL(tmp))); |
| @@ -280,27 +280,27 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 280 | SY_APPLY_OP_FROM_STACK(); | 280 | SY_APPLY_OP_FROM_STACK(); |
| 281 | } | 281 | } |
| 282 | if (cond_op_i == 0 || sy_op_peek() != '(') { | 282 | if (cond_op_i == 0 || sy_op_peek() != '(') { |
| 283 | cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; | 283 | cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; |
| 284 | } | 284 | } |
| 285 | cond_op_i--; | 285 | cond_op_i--; |
| 286 | goto yyc_cond_op; | 286 | goto yyc_cond_op; |
| 287 | } | 287 | } |
| 288 | <cond_op> ";" { | 288 | <cond_op> ";" { |
| 289 | while (cond_op_i) { | 289 | while (cond_op_i) { |
| 290 | if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; } | 290 | if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; } |
| 291 | SY_APPLY_OP_FROM_STACK(); | 291 | SY_APPLY_OP_FROM_STACK(); |
| 292 | } | 292 | } |
| 293 | if (cond_res_i > 1) { cs_log_error("invalid condition on line %d", lineno); goto out; } | 293 | if (cond_res_i > 1) { cs_log_error("invalid condition on line %zu", lineno); goto out; } |
| 294 | goto yyc_init; | 294 | goto yyc_init; |
| 295 | } | 295 | } |
| 296 | <cond, cond_op> * { cs_log_error("syntax error in condition on line %d", lineno); goto out; } | 296 | <cond, cond_op> * { cs_log_error("syntax error in condition on line %zu", lineno); goto out; } |
| 297 | 297 | ||
| 298 | <rule> whitespace+ { goto yyc_rule; } | 298 | <rule> whitespace+ { goto yyc_rule; } |
| 299 | <rule> newline / ( newline | whitespace )* "." { lineno++; goto yyc_rule; } | 299 | <rule> newline / ( newline | whitespace )* "." { lineno++; goto yyc_rule; } |
| 300 | <rule> "." @t1 keyword @t2 ( "(" @t3 ( string? | keyword ) @t4 ")" )? { | 300 | <rule> "." @t1 keyword @t2 ( "(" @t3 ( string? | keyword ) @t4 ")" )? { |
| 301 | if (!cond_res[0]) { goto yyc_rule; } | 301 | if (!cond_res[0]) { goto yyc_rule; } |
| 302 | if (kw_i == MAX_KEYWORDS) { | 302 | if (kw_i == MAX_KEYWORDS) { |
| 303 | cs_log_error("too many keywords in rule (more than %d) on line %d", MAX_KEYWORDS, lineno); | 303 | cs_log_error("too many keywords in rule (more than %d) on line %zu", MAX_KEYWORDS, lineno); |
| 304 | goto out; | 304 | goto out; |
| 305 | } | 305 | } |
| 306 | sp_parsed_keyword kw = { | 306 | sp_parsed_keyword kw = { |
| @@ -321,7 +321,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 321 | } else { | 321 | } else { |
| 322 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t3, t4-t3); | 322 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t3, t4-t3); |
| 323 | if (!tmp) { | 323 | if (!tmp) { |
| 324 | cs_log_error("unknown variable on line %d", lineno); | 324 | cs_log_error("unknown variable on line %zu", lineno); |
| 325 | goto out; | 325 | goto out; |
| 326 | } | 326 | } |
| 327 | kw.arg = ZSTR_VAL(tmp); | 327 | kw.arg = ZSTR_VAL(tmp); |
