From 517ba0690dcc9e859a05df2113ce32401a5ab254 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Mon, 30 Sep 2013 23:16:20 +0200 Subject: Clean up const usage to avoid excessive casting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't use const on pointers that hold heap allocated data, because that means functions that free them must cast away the const. Do use const on pointer parameters or fields that needn't be modified. Remove pointer casts that are no longer needed after fixing the constness. Change-Id: I5d206f5019982fd1950bc6d6d07b6062dc24e886 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/1668 Tested-by: jenkins Reviewed-by: Mathias Küster Reviewed-by: Spencer Oliver --- src/helper/command.c | 31 ++++++++++++++----------------- src/helper/command.h | 6 +++--- src/helper/fileio.c | 4 ++-- 3 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src/helper') diff --git a/src/helper/command.c b/src/helper/command.c index a179578..b374187 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -146,17 +146,17 @@ void script_debug(Jim_Interp *interp, const char *name, free(dbg); } -static void script_command_args_free(const char **words, unsigned nwords) +static void script_command_args_free(char **words, unsigned nwords) { for (unsigned i = 0; i < nwords; i++) - free((void *)words[i]); + free(words[i]); free(words); } -static const char **script_command_args_alloc( +static char **script_command_args_alloc( unsigned argc, Jim_Obj * const *argv, unsigned *nwords) { - const char **words = malloc(argc * sizeof(char *)); + char **words = malloc(argc * sizeof(char *)); if (NULL == words) return NULL; @@ -198,7 +198,7 @@ static int script_command_run(Jim_Interp *interp, LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ unsigned nwords; - const char **words = script_command_args_alloc(argc, argv, &nwords); + char **words = script_command_args_alloc(argc, argv, &nwords); if (NULL == words) return JIM_ERR; @@ -299,12 +299,9 @@ static void command_free(struct command *c) command_free(tmp); } - if (c->name) - free((void *)c->name); - if (c->help) - free((void *)c->help); - if (c->usage) - free((void *)c->usage); + free(c->name); + free(c->help); + free(c->usage); free(c); } @@ -362,7 +359,7 @@ static int register_command_handler(struct command_context *cmd_ctx, struct command *c) { Jim_Interp *interp = cmd_ctx->interp; - const char *ocd_name = alloc_printf("ocd_%s", c->name); + char *ocd_name = alloc_printf("ocd_%s", c->name); if (NULL == ocd_name) return JIM_ERR; @@ -370,19 +367,19 @@ static int register_command_handler(struct command_context *cmd_ctx, Jim_CmdProc func = c->handler ? &script_command : &command_unknown; int retval = Jim_CreateCommand(interp, ocd_name, func, c, NULL); - free((void *)ocd_name); + free(ocd_name); if (JIM_OK != retval) return retval; /* we now need to add an overrideable proc */ - const char *override_name = alloc_printf( + char *override_name = alloc_printf( "proc %s {args} {eval ocd_bouncer %s $args}", c->name, c->name); if (NULL == override_name) return JIM_ERR; retval = Jim_Eval_Named(interp, override_name, 0, 0); - free((void *)override_name); + free(override_name); return retval; } @@ -1103,7 +1100,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (help_text) { bool replaced = false; if (nc->help) { - free((void *)nc->help); + free(nc->help); replaced = true; } nc->help = strdup(help_text); @@ -1115,7 +1112,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (usage) { bool replaced = false; if (nc->usage) { - free((void *)nc->usage); + free(nc->usage); replaced = true; } nc->usage = strdup(usage); diff --git a/src/helper/command.h b/src/helper/command.h index e969ad9..0f0edbb 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -162,9 +162,9 @@ struct command_invocation { typedef __COMMAND_HANDLER((*command_handler_t)); struct command { - const char *name; - const char *help; - const char *usage; + char *name; + char *help; + char *usage; struct command *parent; struct command *children; command_handler_t handler; diff --git a/src/helper/fileio.c b/src/helper/fileio.c index 04cfaf5..c6f45e6 100644 --- a/src/helper/fileio.c +++ b/src/helper/fileio.c @@ -33,7 +33,7 @@ #include "fileio.h" struct fileio_internal { - const char *url; + char *url; ssize_t size; enum fileio_type type; enum fileio_access access; @@ -141,7 +141,7 @@ int fileio_close(struct fileio *fileio_p) retval = fileio_close_local(fileio); - free((void *)fileio->url); + free(fileio->url); fileio->url = NULL; free(fileio); -- cgit v1.1