aboutsummaryrefslogtreecommitdiff
path: root/src/helper/log.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/log.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/log.c')
-rw-r--r--src/helper/log.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/helper/log.c b/src/helper/log.c
index b39cb91..a1b46ef 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -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 */