aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>2013-09-30 23:16:20 +0200
committerSpencer Oliver <spen@spen-soft.co.uk>2013-10-31 20:42:34 +0000
commit517ba0690dcc9e859a05df2113ce32401a5ab254 (patch)
tree7f437e78a54eb7cb6af06ed589c8ceef0c5277bf /src/helper
parentc044c601213ee800cffb21e1f53a89285b3346c9 (diff)
downloadriscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.zip
riscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.tar.gz
riscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.tar.bz2
Clean up const usage to avoid excessive casting
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 <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/1668 Tested-by: jenkins Reviewed-by: Mathias Küster <kesmtp@freenet.de> Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/command.c31
-rw-r--r--src/helper/command.h6
-rw-r--r--src/helper/fileio.c4
3 files changed, 19 insertions, 22 deletions
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);