From 924144799f380863aa3b13f444f478eb81dcef6c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 6 May 2022 21:11:28 +0200 Subject: Another constify pass --- src/sp_config_scanner.h | 6 +++--- src/sp_config_scanner.re | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/sp_config_scanner.h b/src/sp_config_scanner.h index 3284713..8ce1fb7 100644 --- a/src/sp_config_scanner.h +++ b/src/sp_config_scanner.h @@ -19,7 +19,7 @@ typedef struct { } sp_parsed_keyword; zend_result sp_config_scan(char *data, zend_result (*process_rule)(sp_parsed_keyword*)); -zend_string *sp_get_arg_string(sp_parsed_keyword *kw); -zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule); +zend_string *sp_get_arg_string(sp_parsed_keyword const *const kw); +zend_string *sp_get_textual_representation(sp_parsed_keyword const *const parsed_rule); -#endif \ No newline at end of file +#endif diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index d7c9884..9f1ac2b 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re @@ -7,7 +7,7 @@ #define cs_log_warning(fmt, ...) sp_log_warn("config", fmt, ##__VA_ARGS__) -zend_string *sp_get_arg_string(sp_parsed_keyword *kw) { +zend_string *sp_get_arg_string(sp_parsed_keyword const *const kw) { if (!kw || !kw->arg) { return NULL; } @@ -33,11 +33,10 @@ zend_string *sp_get_arg_string(sp_parsed_keyword *kw) { return ret; } -zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule) { +zend_string *sp_get_textual_representation(sp_parsed_keyword const *const parsed_rule) { // a rule is "sp.keyword...keyword(arg);\0" size_t len = 3; // sp + ; - sp_parsed_keyword *kw; - for (kw = parsed_rule; kw->kw; kw++) { + for (const sp_parsed_keyword *kw = parsed_rule; kw->kw; kw++) { len++; // . len += kw->kwlen; if (kw->argtype == SP_ARGTYPE_EMPTY) { @@ -47,10 +46,12 @@ zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule) { len += kw->arglen; } } + zend_string *ret = zend_string_alloc(len, 1); char *ptr = ZSTR_VAL(ret); + memcpy(ptr, "sp", 2); ptr += 2; - for (kw = parsed_rule; kw->kw; kw++) { + for (const sp_parsed_keyword *kw = parsed_rule; kw->kw; kw++) { *ptr++ = '.'; memcpy(ptr, kw->kw, kw->kwlen); ptr += kw->kwlen; if (kw->argtype == SP_ARGTYPE_EMPTY || kw->argtype == SP_ARGTYPE_STR || kw->argtype == SP_ARGTYPE_UNKNOWN) { @@ -322,4 +323,4 @@ zend_result sp_config_scan(char *data, zend_result (*process_rule)(sp_parsed_key out: zend_hash_destroy(&vars); return ret; -} \ No newline at end of file +} -- cgit v1.3