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.re | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/sp_config_scanner.re') 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 From 6e853a21c008f1a8a366e41cf25a24cf97f54764 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 15 May 2022 16:48:48 +0200 Subject: Silence a false positive in gcc --- src/sp_config_scanner.cached.c | 2 ++ src/sp_config_scanner.re | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/sp_config_scanner.re') diff --git a/src/sp_config_scanner.cached.c b/src/sp_config_scanner.cached.c index dfcf25f..3114918 100644 --- a/src/sp_config_scanner.cached.c +++ b/src/sp_config_scanner.cached.c @@ -1,6 +1,8 @@ /* Generated by re2c */ #include "php_snuffleupagus.h" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + enum YYCONDTYPE { yycinit, yyccond, diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index 9f1ac2b..6a14a11 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re @@ -1,5 +1,7 @@ #include "php_snuffleupagus.h" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + /*!types:re2c*/ #define cs_log_error(fmt, ...) sp_log_err("config", fmt, ##__VA_ARGS__) -- cgit v1.3