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
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -111,7 +111,7 @@ FILE *open_file_from_path(const char *file, const char *mode)
|
||||
return fopen(file, mode);
|
||||
else {
|
||||
char *full_path = find_file(file);
|
||||
if (full_path == NULL)
|
||||
if (!full_path)
|
||||
return NULL;
|
||||
FILE *fp = NULL;
|
||||
fp = fopen(full_path, mode);
|
||||
@@ -150,12 +150,12 @@ char *get_home_dir(const char *append_path)
|
||||
{
|
||||
char *home = getenv("HOME");
|
||||
|
||||
if (home == NULL) {
|
||||
if (!home) {
|
||||
|
||||
#ifdef _WIN32
|
||||
home = getenv("USERPROFILE");
|
||||
|
||||
if (home == NULL) {
|
||||
if (!home) {
|
||||
|
||||
char homepath[MAX_PATH];
|
||||
char *drive = getenv("HOMEDRIVE");
|
||||
@@ -173,7 +173,7 @@ char *get_home_dir(const char *append_path)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (home == NULL)
|
||||
if (!home)
|
||||
return home;
|
||||
|
||||
char *home_path;
|
||||
|
||||
@@ -199,7 +199,7 @@ int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
|
||||
}
|
||||
if (puthere)
|
||||
*puthere = o;
|
||||
if (o != NULL)
|
||||
if (o)
|
||||
return JIM_OK;
|
||||
else
|
||||
return JIM_ERR;
|
||||
@@ -227,7 +227,7 @@ int jim_getopt_double(struct jim_getopt_info *goi, double *puthere)
|
||||
Jim_Obj *o;
|
||||
double _safe;
|
||||
|
||||
if (puthere == NULL)
|
||||
if (!puthere)
|
||||
puthere = &_safe;
|
||||
|
||||
r = jim_getopt_obj(goi, &o);
|
||||
@@ -245,7 +245,7 @@ int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
|
||||
Jim_Obj *o;
|
||||
jim_wide _safe;
|
||||
|
||||
if (puthere == NULL)
|
||||
if (!puthere)
|
||||
puthere = &_safe;
|
||||
|
||||
r = jim_getopt_obj(goi, &o);
|
||||
@@ -260,7 +260,7 @@ int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struc
|
||||
Jim_Obj *o;
|
||||
int e;
|
||||
|
||||
if (puthere == NULL)
|
||||
if (!puthere)
|
||||
puthere = &_safe;
|
||||
|
||||
e = jim_getopt_obj(goi, &o);
|
||||
@@ -284,7 +284,7 @@ int jim_getopt_enum(struct jim_getopt_info *goi, const char *const *lookup, int
|
||||
Jim_Obj *o;
|
||||
int e;
|
||||
|
||||
if (puthere == NULL)
|
||||
if (!puthere)
|
||||
puthere = &_safe;
|
||||
e = jim_getopt_obj(goi, &o);
|
||||
if (e == JIM_OK)
|
||||
|
||||
@@ -108,7 +108,7 @@ static void log_puts(enum log_levels level,
|
||||
}
|
||||
|
||||
f = strrchr(file, '/');
|
||||
if (f != NULL)
|
||||
if (f)
|
||||
file = f + 1;
|
||||
|
||||
if (strlen(string) > 0) {
|
||||
@@ -163,7 +163,7 @@ void log_printf(enum log_levels level,
|
||||
va_start(ap, format);
|
||||
|
||||
string = alloc_vprintf(format, ap);
|
||||
if (string != NULL) {
|
||||
if (string) {
|
||||
log_puts(level, file, line, function, string);
|
||||
free(string);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ COMMAND_HANDLER(handle_log_output_command)
|
||||
}
|
||||
if (CMD_ARGC == 1) {
|
||||
FILE *file = fopen(CMD_ARGV[0], "w");
|
||||
if (file == NULL) {
|
||||
if (!file) {
|
||||
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ void log_init(void)
|
||||
/* set defaults for daemon configuration,
|
||||
* if not set by cmdline or cfgfile */
|
||||
char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
|
||||
if (NULL != debug_env) {
|
||||
if (debug_env) {
|
||||
int value;
|
||||
int retval = parse_int(debug_env, &value);
|
||||
if (retval == ERROR_OK &&
|
||||
@@ -296,7 +296,7 @@ void log_init(void)
|
||||
debug_level = value;
|
||||
}
|
||||
|
||||
if (log_output == NULL)
|
||||
if (!log_output)
|
||||
log_output = stderr;
|
||||
|
||||
start = last_time = timeval_ms();
|
||||
@@ -322,7 +322,7 @@ int log_add_callback(log_callback_fn fn, void *priv)
|
||||
/* alloc memory, it is safe just to return in case of an error, no need for the caller to
|
||||
*check this */
|
||||
cb = malloc(sizeof(struct log_callback));
|
||||
if (cb == NULL)
|
||||
if (!cb)
|
||||
return ERROR_BUF_TOO_SMALL;
|
||||
|
||||
/* add item to the beginning of the linked list */
|
||||
@@ -367,7 +367,7 @@ char *alloc_vprintf(const char *fmt, va_list ap)
|
||||
* other code depend on that. They should be probably be fixed, but for
|
||||
* now reserve the extra byte. */
|
||||
string = malloc(len + 2);
|
||||
if (string == NULL)
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
/* do the real work */
|
||||
|
||||
@@ -75,7 +75,7 @@ static char *find_exe_path(void)
|
||||
do {
|
||||
#if IS_WIN32 && !IS_CYGWIN
|
||||
exepath = malloc(MAX_PATH);
|
||||
if (exepath == NULL)
|
||||
if (!exepath)
|
||||
break;
|
||||
GetModuleFileName(NULL, exepath, MAX_PATH);
|
||||
|
||||
@@ -87,7 +87,7 @@ static char *find_exe_path(void)
|
||||
|
||||
#elif IS_DARWIN
|
||||
exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
|
||||
if (exepath == NULL)
|
||||
if (!exepath)
|
||||
break;
|
||||
if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
|
||||
free(exepath);
|
||||
@@ -99,7 +99,7 @@ static char *find_exe_path(void)
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
char *path = malloc(PATH_MAX);
|
||||
if (path == NULL)
|
||||
if (!path)
|
||||
break;
|
||||
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
size_t size = PATH_MAX;
|
||||
@@ -117,14 +117,14 @@ static char *find_exe_path(void)
|
||||
#elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */
|
||||
/* Try Unices in order of likelihood. */
|
||||
exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */
|
||||
if (exepath == NULL)
|
||||
if (!exepath)
|
||||
exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */
|
||||
if (exepath == NULL)
|
||||
if (!exepath)
|
||||
exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */
|
||||
#endif
|
||||
} while (0);
|
||||
|
||||
if (exepath != NULL) {
|
||||
if (exepath) {
|
||||
/* Strip executable file name, leaving path */
|
||||
*strrchr(exepath, '/') = '\0';
|
||||
} else {
|
||||
@@ -163,7 +163,7 @@ static char *find_relative_path(const char *from, const char *to)
|
||||
if (from[0] != '/')
|
||||
i++;
|
||||
char *next = strchr(from, '/');
|
||||
if (next == NULL)
|
||||
if (!next)
|
||||
break;
|
||||
from = next + 1;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
void *clear_malloc(size_t size)
|
||||
{
|
||||
void *t = malloc(size);
|
||||
if (t != NULL)
|
||||
if (t)
|
||||
memset(t, 0x00, size);
|
||||
return t;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ void *clear_malloc(size_t size)
|
||||
void *fill_malloc(size_t size)
|
||||
{
|
||||
void *t = malloc(size);
|
||||
if (t != NULL) {
|
||||
if (t) {
|
||||
/* We want to initialize memory to some known bad state.
|
||||
* 0 and 0xff yields 0 and -1 as integers, which often
|
||||
* have meaningful values. 0x5555... is not often a valid
|
||||
@@ -124,7 +124,7 @@ char *strndup(const char *s, size_t n)
|
||||
size_t len = strnlen(s, n);
|
||||
char *new = malloc(len + 1);
|
||||
|
||||
if (new == NULL)
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
new[len] = '\0';
|
||||
@@ -148,7 +148,7 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time
|
||||
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
|
||||
|
||||
/* calculate how long we need to wait in milliseconds */
|
||||
if (tv == NULL)
|
||||
if (!tv)
|
||||
ms_total = INFINITE;
|
||||
else {
|
||||
ms_total = tv->tv_sec * 1000;
|
||||
|
||||
Reference in New Issue
Block a user