From 9c2c9d805d92c846f472f994efb50e1ad2fb60b6 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 7 Feb 2018 11:57:16 +0100 Subject: Use assertions for things that should never happen --- src/sp_disabled_functions.c | 7 ++++--- src/sp_var_parser.c | 10 ++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index 779240e..4d94a97 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c @@ -107,7 +107,6 @@ static const sp_list_node* get_config_node(const char* builtin_name) { .config_disabled_constructs->construct_include; } ZEND_ASSUME(0); - return NULL; // This should never happen. } static bool is_param_matching(zend_execute_data* execute_data, @@ -360,6 +359,8 @@ bool should_drop_on_ret(zval* return_value, sp_disabled_function const* const config_node = (sp_disabled_function*)(config->data); + assert(config_node->function || config_node->r_function); + if (config_node->function) { if (0 != strcmp(config_node->function, complete_path_function)) { goto next; @@ -443,14 +444,14 @@ static int hook_functions(const sp_list_node* config) { const sp_pcre* function_name_regexp = ((sp_disabled_function*)config->data)->r_function; + assert(function_name || function_name_regexp); + if (NULL != function_name) { // hook function by name HOOK_FUNCTION(function_name, disabled_functions_hook, PHP_FN(check_disabled_function)); } else if (NULL != function_name_regexp) { // hook function by regexp HOOK_FUNCTION_BY_REGEXP(function_name_regexp, disabled_functions_hook, PHP_FN(check_disabled_function)); - } else { - return FAILURE; } config = config->next; diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c index 8e5bdb1..b57386e 100644 --- a/src/sp_var_parser.c +++ b/src/sp_var_parser.c @@ -24,9 +24,8 @@ static bool is_var_name_valid(const char *name) { static sp_pcre *regexp_const = NULL; static sp_pcre *regexp_var = NULL; - if (!name) { - return false; - } + assert(name); + if (NULL == regexp_var || NULL == regexp_const) { regexp_var = sp_pcre_compile(REGEXP_VAR); regexp_const = sp_pcre_compile(REGEXP_CONST); @@ -46,9 +45,8 @@ static int create_var(sp_tree *tree, const char *restrict value, const char *restrict idx) { sp_tree *var_node = NULL; - if (!tree) { - return -1; - } + assert(tree); + if (tree->next == NULL && tree->type == UNDEFINED) { var_node = tree; } else { -- cgit v1.3