diff --git a/src/sp_config.c b/src/sp_config.c index 2d2631a5..de58c2a0 100644 --- a/src/sp_config.c +++ b/src/sp_config.c @@ -90,7 +90,7 @@ zend_result sp_process_rule(sp_parsed_keyword *parsed_rule, const sp_config_keyw if (!found_kw) { zend_string *kwname = zend_string_init(kw->kw, kw->kwlen, 0); - sp_log_err("config", "Unexpected keyword '%s' on line %d", ZSTR_VAL(kwname), kw->lineno); + sp_log_err("config", "Unexpected keyword '%s' on line %zu", ZSTR_VAL(kwname), kw->lineno); zend_string_release_ex(kwname, 0); return FAILURE; } diff --git a/src/sp_config_scanner.h b/src/sp_config_scanner.h index 560ea6e3..dda3dc26 100644 --- a/src/sp_config_scanner.h +++ b/src/sp_config_scanner.h @@ -15,7 +15,7 @@ typedef struct { const char *arg; // optional argument / can be not null terminated size_t arglen; sp_argtype argtype; - long lineno; + size_t lineno; } sp_parsed_keyword; zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_parsed_keyword*)); diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index 8f0b24eb..f9a6ce9b 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re @@ -90,11 +90,11 @@ static void str_dtor(zval *zv) { // sy_ functions and macros are helpers for the shunting yard algorithm #define sy_res_push(val) \ - if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ + if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ cond_res[cond_res_i++] = val; #define sy_res_pop() cond_res[--cond_res_i] #define sy_op_push(op) \ - if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ + if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ cond_op[cond_op_i++] = op; #define sy_op_pop() cond_op[--cond_op_i] #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) { #define SY_APPLY_OP_FROM_STACK() \ char op = sy_op_pop(); \ int unary = (op == '!'); \ - if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %d", lineno); goto out; } \ + if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %zu", lineno); goto out; } \ int a = sy_res_pop(); \ int b = unary ? 0 : sy_res_pop(); \ 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 int cond_op_i = 0; int cond = yycinit; - long lineno = 1; + size_t lineno = 1; /*!stags:re2c format = 'const char *@@;\n'; */ /*!re2c @@ -189,7 +189,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars keyword = [a-zA-Z][a-zA-Z0-9_]*; string = ["] ("\\"["] | [^"\r\n\x00])* ["]; - * { cs_log_error("parser error on line %d", lineno); goto out; } + * { cs_log_error("parser error on line %zu", lineno); goto out; } whitespace+ { goto yyc_init; } [;#] [^\r\n\x00]* { goto yyc_init; } newline { lineno++; goto yyc_init; } @@ -212,19 +212,19 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars ( "@log" | "@info" ) whitespace+ @t1 string @t2 ";" { if (!cond_res[0]) { goto yyc_init; } TMPSTR(tmpstr, t2, t1); - cs_log_info("[line %d]: %s", lineno, tmpstr); + cs_log_info("[line %zu]: %s", lineno, tmpstr); goto yyc_init; } ( "@warn" | "@warning" ) whitespace+ @t1 string @t2 ";" { if (!cond_res[0]) { goto yyc_init; } TMPSTR(tmpstr, t2, t1); - cs_log_warning("[line %d]: %s", lineno, tmpstr); + cs_log_warning("[line %zu]: %s", lineno, tmpstr); goto yyc_init; } ( "@err" | "@error" ) whitespace+ @t1 string @t2 ";" { if (!cond_res[0]) { goto yyc_init; } TMPSTR(tmpstr, t2, t1); - cs_log_error("[line %d]: %s", lineno, tmpstr); + cs_log_error("[line %zu]: %s", lineno, tmpstr); goto out; } @@ -236,7 +236,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars int is_loaded = (zend_hash_str_find_ptr(&module_registry, t3+1, t4-t3-2) != NULL); sy_res_push(is_loaded); } else { - cs_log_error("unknown function in condition on line %d", lineno); + cs_log_error("unknown function in condition on line %zu", lineno); goto out; } goto yyc_cond_op; @@ -244,7 +244,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars @t1 keyword @t2 { zend_string *tmp = zend_hash_str_find_ptr(&vars, t1, t2-t1); if (!tmp) { - cs_log_error("unknown variable in condition on line %d", lineno); + cs_log_error("unknown variable in condition on line %zu", lineno); goto out; } 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 SY_APPLY_OP_FROM_STACK(); } if (cond_op_i == 0 || sy_op_peek() != '(') { - cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; + cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; } cond_op_i--; goto yyc_cond_op; } ";" { while (cond_op_i) { - if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; } + if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; } SY_APPLY_OP_FROM_STACK(); } - if (cond_res_i > 1) { cs_log_error("invalid condition on line %d", lineno); goto out; } + if (cond_res_i > 1) { cs_log_error("invalid condition on line %zu", lineno); goto out; } goto yyc_init; } - * { cs_log_error("syntax error in condition on line %d", lineno); goto out; } + * { cs_log_error("syntax error in condition on line %zu", lineno); goto out; } whitespace+ { goto yyc_rule; } newline / ( newline | whitespace )* "." { lineno++; goto yyc_rule; } "." @t1 keyword @t2 ( "(" @t3 ( string? | keyword ) @t4 ")" )? { if (!cond_res[0]) { goto yyc_rule; } if (kw_i == MAX_KEYWORDS) { - cs_log_error("too many keywords in rule (more than %d) on line %d", MAX_KEYWORDS, lineno); + cs_log_error("too many keywords in rule (more than %d) on line %zu", MAX_KEYWORDS, lineno); goto out; } sp_parsed_keyword kw = { @@ -321,7 +321,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars } else { zend_string *tmp = zend_hash_str_find_ptr(&vars, t3, t4-t3); if (!tmp) { - cs_log_error("unknown variable on line %d", lineno); + cs_log_error("unknown variable on line %zu", lineno); goto out; } kw.arg = ZSTR_VAL(tmp); diff --git a/src/sp_ini.c b/src/sp_ini.c index 8860a929..cfbc615b 100644 --- a/src/sp_ini.c +++ b/src/sp_ini.c @@ -97,7 +97,7 @@ static bool /* success */ sp_ini_check(zend_string *const restrict varname, zend if (entry->msg) { sp_log_ini_check_violation("%s", ZSTR_VAL(entry->msg)); } else { - sp_log_ini_check_violation("INI value %lld for `%s` out of range", lvalue, ZSTR_VAL(entry->key)); + sp_log_ini_check_violation("INI value " ZEND_LONG_FMT " for `%s` out of range", lvalue, ZSTR_VAL(entry->key)); } return simulation; } diff --git a/src/sp_utils.h b/src/sp_utils.h index 36caa524..1146db3b 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h @@ -71,6 +71,11 @@ extern int sp_debug_stderr; #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") const char *get_ipaddr(void); +#if defined __has_attribute +# if __has_attribute (__format__) + __attribute__((__format__(printf, 4, 5))) +# endif +#endif void sp_log_msgf(char const* const restrict feature, int level, int type, char const* const restrict fmt, ...); int compute_hash(char const* const restrict filename, char *restrict file_hash); const zend_string *sp_zval_to_zend_string(const zval *);