From 88355dd338835f7a59415ecb2e7e970658f3867f Mon Sep 17 00:00:00 2001 From: twosee Date: Sun, 7 Jun 2020 17:01:19 +0800 Subject: Constify char * arguments of APIs Closes GH-5676. --- sapi/phpdbg/phpdbg.c | 2 +- sapi/phpdbg/phpdbg_cmd.c | 20 +++++++------------- sapi/phpdbg/phpdbg_cmd.h | 4 ++-- sapi/phpdbg/phpdbg_print.c | 12 ++++++------ sapi/phpdbg/phpdbg_print.h | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) (limited to 'sapi/phpdbg') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 78aa34f524..ea0653fd25 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -772,7 +772,7 @@ static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *s } /* }}} */ -static void php_sapi_phpdbg_log_message(char *message, int syslog_type_int) /* {{{ */ +static void php_sapi_phpdbg_log_message(const char *message, int syslog_type_int) /* {{{ */ { /* * We must not request TSRM before being booted diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c index 61f17d1c0e..757d48e739 100644 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@ -737,10 +737,9 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async return SUCCESS; } /* }}} */ -PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */ +PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */ { char buf[PHPDBG_MAX_CMD]; - char *cmd = NULL; char *buffer = NULL; if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) != PHPDBG_IS_STOPPING) { @@ -755,11 +754,12 @@ PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */ #endif { phpdbg_write("prompt", "", "%s", phpdbg_get_prompt()); - phpdbg_consume_stdin_line(cmd = buf); + phpdbg_consume_stdin_line(buf); + buffer = estrdup(buf); } #ifdef HAVE_PHPDBG_READLINE else { - cmd = readline(phpdbg_get_prompt()); + char *cmd = readline(phpdbg_get_prompt()); PHPDBG_G(last_was_newline) = 1; if (!cmd) { @@ -768,19 +768,13 @@ PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */ } add_history(cmd); + buffer = estrdup(cmd); + free(cmd); } #endif } else { - cmd = buffered; + buffer = estrdup(buffered); } - - buffer = estrdup(cmd); - -#ifdef HAVE_PHPDBG_READLINE - if (!buffered && cmd && !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd)) { - free(cmd); - } -#endif } if (buffer && isspace(*buffer)) { diff --git a/sapi/phpdbg/phpdbg_cmd.h b/sapi/phpdbg/phpdbg_cmd.h index dd80e61db3..3cc07d1a70 100644 --- a/sapi/phpdbg/phpdbg_cmd.h +++ b/sapi/phpdbg/phpdbg_cmd.h @@ -125,8 +125,8 @@ typedef struct { /* * Input Management */ -PHPDBG_API char* phpdbg_read_input(char *buffered); -PHPDBG_API void phpdbg_destroy_input(char**); +PHPDBG_API char *phpdbg_read_input(const char *buffered); +PHPDBG_API void phpdbg_destroy_input(char **input); PHPDBG_API int phpdbg_ask_user_permission(const char *question); /** diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 7cc84b72dc..df925b6402 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -375,7 +375,7 @@ void phpdbg_print_opcodes_class(const char *class) { phpdbg_print_opcodes_ce(ce); } -PHPDBG_API void phpdbg_print_opcodes(char *function) +PHPDBG_API void phpdbg_print_opcodes(const char *function) { if (function == NULL) { phpdbg_print_opcodes_main(); @@ -401,12 +401,12 @@ PHPDBG_API void phpdbg_print_opcodes(char *function) } } ZEND_HASH_FOREACH_END(); } else { - function = zend_str_tolower_dup(function, strlen(function)); + char *function_lowercase = zend_str_tolower_dup(function, strlen(function)); - if (strstr(function, "::") == NULL) { - phpdbg_print_opcodes_function(function, strlen(function)); + if (strstr(function_lowercase, "::") == NULL) { + phpdbg_print_opcodes_function(function_lowercase, strlen(function_lowercase)); } else { - char *method_name, *class_name = strtok(function, "::"); + char *method_name, *class_name = strtok(function_lowercase, "::"); if ((method_name = strtok(NULL, "::")) == NULL) { phpdbg_print_opcodes_class(class_name); } else { @@ -414,6 +414,6 @@ PHPDBG_API void phpdbg_print_opcodes(char *function) } } - efree(function); + efree(function_lowercase); } } diff --git a/sapi/phpdbg/phpdbg_print.h b/sapi/phpdbg/phpdbg_print.h index 79a77ad2a6..14f5bf6939 100644 --- a/sapi/phpdbg/phpdbg_print.h +++ b/sapi/phpdbg/phpdbg_print.h @@ -33,7 +33,7 @@ PHPDBG_PRINT(method); PHPDBG_PRINT(func); PHPDBG_PRINT(stack); -PHPDBG_API void phpdbg_print_opcodes(char *function); +PHPDBG_API void phpdbg_print_opcodes(const char *function); extern const phpdbg_command_t phpdbg_print_commands[]; -- cgit v1.2.1