aboutsummaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2021-07-03 18:51:20 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-07-24 10:37:49 +0100
commit08ee7bb982b16742f52cfdc6c649d82ffa2eb177 (patch)
treea824d376b774499303f00cffb201e35b01830d98 /src/helper/command.c
parentb159f5cdedd70fff9309722e927be670845f4df5 (diff)
downloadriscv-openocd-08ee7bb982b16742f52cfdc6c649d82ffa2eb177.zip
riscv-openocd-08ee7bb982b16742f52cfdc6c649d82ffa2eb177.tar.gz
riscv-openocd-08ee7bb982b16742f52cfdc6c649d82ffa2eb177.tar.bz2
openocd: fix simple cases of NULL comparison
There are more than 1000 NULL comparisons to be aligned to the coding style. For recurrent NULL comparison it's preferable using trivial scripts in order to minimize the review effort. Patch generated automatically with the command: sed -i PATTERN $(find src/ -type f) where PATTERN is in the list: 's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g' Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6350 Tested-by: jenkins
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 0c76450..b3b53ae 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -118,7 +118,7 @@ static struct log_capture_state *command_log_capture_start(Jim_Interp *interp)
*/
static void command_log_capture_finish(struct log_capture_state *state)
{
- if (NULL == state)
+ if (!state)
return;
log_remove_callback(tcl_output, state);
@@ -175,7 +175,7 @@ static int workaround_createcommand(Jim_Interp *interp, const char *cmdName,
static int command_retval_set(Jim_Interp *interp, int retval)
{
int *return_retval = Jim_GetAssocData(interp, "retval");
- if (return_retval != NULL)
+ if (return_retval)
*return_retval = retval;
return (retval == ERROR_OK) ? JIM_OK : retval;
@@ -213,7 +213,7 @@ static char **script_command_args_alloc(
unsigned argc, Jim_Obj * const *argv, unsigned *nwords)
{
char **words = malloc(argc * sizeof(char *));
- if (NULL == words)
+ if (!words)
return NULL;
unsigned i;
@@ -234,7 +234,7 @@ struct command_context *current_command_context(Jim_Interp *interp)
{
/* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
- if (NULL == cmd_ctx) {
+ if (!cmd_ctx) {
/* Tcl can invoke commands directly instead of via command_run_line(). This would
* happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script.
@@ -285,7 +285,7 @@ static struct command *command_new(struct command_context *cmd_ctx,
full_name);
struct command *c = calloc(1, sizeof(struct command));
- if (NULL == c)
+ if (!c)
return NULL;
c->name = strdup(cr->name);
@@ -369,16 +369,16 @@ int __register_commands(struct command_context *cmd_ctx, const char *cmd_prefix,
const struct command_registration *cr = cmds + i;
struct command *c = NULL;
- if (NULL != cr->name) {
+ if (cr->name) {
c = register_command(cmd_ctx, cmd_prefix, cr);
- if (NULL == c) {
+ if (!c) {
retval = ERROR_FAIL;
break;
}
c->jim_handler_data = data;
c->jim_override_target = override_target;
}
- if (NULL != cr->chain) {
+ if (cr->chain) {
if (cr->name) {
if (cmd_prefix) {
char *new_prefix = alloc_printf("%s %s", cmd_prefix, cr->name);
@@ -670,7 +670,7 @@ int command_run_linef(struct command_context *context, const char *format, ...)
va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
- if (string != NULL) {
+ if (string) {
retval = command_run_line(context, string);
free(string);
}
@@ -696,7 +696,7 @@ struct command_context *copy_command_context(struct command_context *context)
void command_done(struct command_context *cmd_ctx)
{
- if (NULL == cmd_ctx)
+ if (!cmd_ctx)
return;
free(cmd_ctx);
@@ -709,7 +709,7 @@ static int jim_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file);
- if (full_path == NULL)
+ if (!full_path)
return JIM_ERR;
Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path));
free(full_path);
@@ -816,8 +816,8 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
/* If the match string occurs anywhere, we print out
* stuff for this command. */
bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
- ((c->usage != NULL) && (strstr(c->usage, cmd_match) != NULL)) ||
- ((c->help != NULL) && (strstr(c->help, cmd_match) != NULL));
+ ((c->usage) && (strstr(c->usage, cmd_match) != NULL)) ||
+ ((c->help) && (strstr(c->help, cmd_match) != NULL));
if (is_match) {
if (c->usage && strlen(c->usage) > 0) {
@@ -870,7 +870,7 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
} else
msg = alloc_printf("%s", c->help ? c->help : "");
- if (NULL != msg) {
+ if (msg) {
command_help_show_wrap(msg, n + 3, n + 3);
free(msg);
} else
@@ -899,7 +899,7 @@ COMMAND_HANDLER(handle_help_command)
}
}
- if (cmd_match == NULL) {
+ if (!cmd_match) {
LOG_ERROR("unable to build search string");
return -ENOMEM;
}
@@ -1286,7 +1286,7 @@ struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp
INIT_LIST_HEAD(context->help_list);
/* Create a jim interpreter if we were not handed one */
- if (interp == NULL) {
+ if (!interp) {
/* Create an interpreter */
interp = Jim_CreateInterp();
/* Add all the Jim core commands */