summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2010-08-21 13:52:25 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2010-08-21 13:52:25 +0000
commite14093a9f933fef1826d4036bf9991387020405d (patch)
tree2cf94275779e4b455c48438c717806426b1f9595
parent503ac8ec06eda77e117dea0e7e23f76e956b3733 (diff)
downloadlibast-e14093a9f933fef1826d4036bf9991387020405d.tar.gz
Convert (hopefully) all comparisons to NULL
Apply badzero.cocci, badnull.coci and badnull2.cocci This should convert all cases where there's a comparison to NULL to simpler forms. This patch applies the following transformations: code before patch ||code after patch =============================================================== return a == NULL; return !a; return a != NULL; return !!a; func(a == NULL); func(!a); func(a != NULL); func(!!a); b = a == NULL; b = !a; b = a != NULL; b = !!a; b = a == NULL ? c : d; b = !a ? c : d; b = a != NULL ? c : d; b = a ? c : d; other cases: a == NULL !a a != NULL a SVN revision: 51487
-rw-r--r--src/conf.c40
-rw-r--r--src/mem.c24
-rw-r--r--src/msgs.c8
-rw-r--r--src/options.c14
-rw-r--r--src/snprintf.c4
-rw-r--r--src/socket.c22
-rw-r--r--src/str.c3
-rw-r--r--src/strings.c20
-rw-r--r--src/tok.c2
-rw-r--r--src/url.c24
-rw-r--r--src/ustr.c3
-rw-r--r--test/test.c46
12 files changed, 104 insertions, 106 deletions
diff --git a/src/conf.c b/src/conf.c
index 1d2e74b..cd4ff2c 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -242,7 +242,7 @@ spifconf_put_var(spif_charptr_t var, spif_charptr_t val)
{
spifconf_var_t *v, *loc = NULL, *tmp;
- ASSERT(var != NULL);
+ ASSERT(!!var);
D_CONF(("var == \"%s\", val == \"%s\"\n", var, val));
for (v = spifconf_vars; v; loc = v, v = v->next) {
@@ -277,7 +277,7 @@ spifconf_put_var(spif_charptr_t var, spif_charptr_t val)
((loc) ? (loc->var) : ((spif_charptr_t) "-beginning-")),
((v) ? (v->var) : ((spif_charptr_t) "-end-"))));
tmp = spifconf_new_var();
- if (loc == NULL) {
+ if (!loc) {
tmp->next = spifconf_vars;
spifconf_vars = tmp;
} else {
@@ -338,7 +338,7 @@ builtin_exec(spif_charptr_t param)
strcat((char *) Command, " >");
strcat((char *) Command, (char *) OutFile);
system((char *) Command);
- if ((fp = fdopen(fd, "rb")) != NULL) {
+ if ((fp = fdopen(fd, "rb"))) {
fseek(fp, 0, SEEK_END);
fsize = ftell(fp);
rewind(fp);
@@ -437,7 +437,7 @@ builtin_dirscan(spif_charptr_t param)
*buff = 0;
n = CONFIG_BUFF;
- for (i = 0; (dp = readdir(dirp)) != NULL;) {
+ for (i = 0; (dp = readdir(dirp));) {
spif_char_t fullname[PATH_MAX];
snprintf((char *) fullname, sizeof(fullname), "%s/%s", dir, dp->d_name);
@@ -498,7 +498,7 @@ spifconf_shell_expand(spif_charptr_t s)
const spif_uint32_t max = CONFIG_BUFF - 1;
spif_charptr_t Command, Output, EnvVar;
- ASSERT_RVAL(s != NULL, (spif_charptr_t) NULL);
+ ASSERT_RVAL(!!s, (spif_charptr_t) NULL);
#if 0
newbuff = (spif_charptr_t) MALLOC(CONFIG_BUFF);
@@ -557,7 +557,7 @@ spifconf_shell_expand(spif_charptr_t s)
break;
case '%':
D_CONF(("%% detected.\n"));
- for (k = 0, pbuff++; builtins[k].name != NULL; k++) {
+ for (k = 0, pbuff++; builtins[k].name; k++) {
D_PARSE(("Checking for function %%%s, pbuff == \"%s\"\n", builtins[k].name, pbuff));
l = strlen((char *) builtins[k].name);
if (!strncasecmp((char *) builtins[k].name, (char *) pbuff, l)
@@ -567,7 +567,7 @@ spifconf_shell_expand(spif_charptr_t s)
break;
}
}
- if (builtins[k].name == NULL) {
+ if (!builtins[k].name) {
newbuff[j] = *pbuff;
} else {
D_CONF(("Call to built-in function %s detected.\n", builtins[k].name));
@@ -729,7 +729,7 @@ spifconf_find_file(const spif_charptr_t file, const spif_charptr_t dir, const sp
spif_int32_t len, maxpathlen;
struct stat fst;
- REQUIRE_RVAL(file != NULL, NULL);
+ REQUIRE_RVAL(!!file, NULL);
getcwd((char *) name, PATH_MAX);
D_CONF(("spifconf_find_file(\"%s\", \"%s\", \"%s\") called from directory \"%s\".\n",
@@ -765,11 +765,11 @@ spifconf_find_file(const spif_charptr_t file, const spif_charptr_t dir, const sp
return ((spif_charptr_t) NULL);
}
- for (path = pathlist; path != NULL && *path != '\0'; path = p) {
+ for (path = pathlist; path && *path != '\0'; path = p) {
short n;
/* Calculate the length of the next directory in the path */
- if ((p = (spif_charptr_t) strchr((char *) path, ':')) != NULL) {
+ if ((p = (spif_charptr_t)strchr((char *)path, ':'))) {
n = p++ - path;
} else {
n = strlen((char *) path);
@@ -808,7 +808,7 @@ spifconf_open_file(spif_charptr_t name)
spif_charptr_t begin_ptr, end_ptr;
spif_stridx_t testlen;
- ASSERT_RVAL(name != NULL, NULL);
+ ASSERT_RVAL(!!name, NULL);
snprintf((char *) test, sizeof(test), "<%s-", libast_program_name);
testlen = (spif_stridx_t) strlen((char *) test);
@@ -816,7 +816,7 @@ spifconf_open_file(spif_charptr_t name)
/* Read first line from config file. Using spif_str_new_from_fp() would read the
* whole file, so we don't do that here. */
fp = fopen((char *) name, "rt");
- REQUIRE_RVAL(fp != NULL, NULL);
+ REQUIRE_RVAL(!!fp, NULL);
fgets((char *) buff, 256, fp);
ver_str = spif_str_new_from_ptr(buff);
@@ -857,12 +857,12 @@ spifconf_parse_line(FILE * fp, spif_charptr_t buff)
unsigned char id;
void *state = NULL;
- ASSERT(buff != NULL);
+ ASSERT(!!buff);
if (!(*buff) || *buff == '\n' || *buff == '#' || *buff == '<') {
SPIFCONF_PARSE_RET();
}
- if (fp == NULL) {
+ if (!fp) {
file_push(NULL, (spif_charptr_t) "<argv>", NULL, 0, 0);
ctx_begin(1);
buff = spiftool_get_pword(2, buff);
@@ -884,7 +884,7 @@ spifconf_parse_line(FILE * fp, spif_charptr_t buff)
spifconf_shell_expand((spif_charptr_t) buff);
path = spiftool_get_word(2, buff + 1);
- if ((fp = spifconf_open_file(path)) == NULL) {
+ if (!(fp = spifconf_open_file(path))) {
libast_print_error("Parsing file %s, line %lu: Unable to locate %%included config file %s (%s), continuing\n", file_peek_path(),
file_peek_line(), path, strerror(errno));
} else {
@@ -906,7 +906,7 @@ spifconf_parse_line(FILE * fp, spif_charptr_t buff)
spiftool_get_pword(2, buff), file_peek_path(), fname);
system((char *) cmd);
fp = fdopen(fd, "rt");
- if (fp != NULL) {
+ if (fp) {
fclose(file_peek_fp());
file_poke_fp(fp);
file_poke_preproc(1);
@@ -953,12 +953,12 @@ spifconf_parse(spif_charptr_t conf_name, const spif_charptr_t dir, const spif_ch
spif_charptr_t name = NULL, p = (spif_charptr_t) ".";
spif_char_t buff[CONFIG_BUFF], orig_dir[PATH_MAX];
- REQUIRE_RVAL(conf_name != NULL, 0);
+ REQUIRE_RVAL(!!conf_name, 0);
*orig_dir = 0;
if (path) {
- if ((name = spifconf_find_file(conf_name, dir, path)) != NULL) {
- if ((p = (spif_charptr_t) strrchr((char *) name, '/')) != NULL) {
+ if ((name = spifconf_find_file(conf_name, dir, path))) {
+ if ((p = (spif_charptr_t)strrchr((char *)name, '/'))) {
getcwd((char *) orig_dir, PATH_MAX);
*p = 0;
p = name;
@@ -970,7 +970,7 @@ spifconf_parse(spif_charptr_t conf_name, const spif_charptr_t dir, const spif_ch
return NULL;
}
}
- if ((fp = spifconf_open_file(conf_name)) == NULL) {
+ if (!(fp = spifconf_open_file(conf_name))) {
return NULL;
}
/* Line count starts at 1 because spifconf_open_file() parses the first line. */
diff --git a/src/mem.c b/src/mem.c
index 2b4a877..e8e5d3c 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -146,9 +146,9 @@ memrec_add_var(memrec_t *memrec, const spif_charptr_t filename, unsigned long li
{
register ptr_t *p;
- ASSERT(memrec != NULL);
+ ASSERT(!!memrec);
memrec->cnt++;
- if ((memrec->ptrs = (ptr_t *) realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt)) == NULL) {
+ if (!(memrec->ptrs = (ptr_t *)realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt))) {
D_MEM(("Unable to reallocate pointer list -- %s\n", strerror(errno)));
}
p = memrec->ptrs + memrec->cnt - 1;
@@ -181,8 +181,8 @@ memrec_find_var(memrec_t *memrec, const void *ptr)
register ptr_t *p;
register unsigned long i;
- ASSERT_RVAL(memrec != NULL, NULL);
- REQUIRE_RVAL(ptr != NULL, NULL);
+ ASSERT_RVAL(!!memrec, NULL);
+ REQUIRE_RVAL(!!ptr, NULL);
for (i = 0, p = memrec->ptrs; i < memrec->cnt; i++, p++) {
if (p->ptr == ptr) {
@@ -215,12 +215,12 @@ memrec_rem_var(memrec_t *memrec, const spif_charptr_t var, const spif_charptr_t
{
register ptr_t *p;
- ASSERT(memrec != NULL);
+ ASSERT(!!memrec);
USE_VAR(var);
USE_VAR(filename);
USE_VAR(line);
- if ((p = memrec_find_var(memrec, ptr)) == NULL) {
+ if (!(p = memrec_find_var(memrec, ptr))) {
D_MEM(("ERROR: File %s, line %d attempted to free variable %s (%10p) which was not allocated with MALLOC/REALLOC\n",
filename, line, var, ptr));
return;
@@ -256,10 +256,10 @@ memrec_chg_var(memrec_t *memrec, const spif_charptr_t var, const spif_charptr_t
{
register ptr_t *p;
- ASSERT(memrec != NULL);
+ ASSERT(!!memrec);
USE_VAR(var);
- if ((p = memrec_find_var(memrec, oldp)) == NULL) {
+ if (!(p = memrec_find_var(memrec, oldp))) {
D_MEM(("ERROR: File %s, line %d attempted to realloc variable %s (%10p) which was not allocated with MALLOC/REALLOC\n", filename,
line, var, oldp));
return;
@@ -292,7 +292,7 @@ memrec_dump_pointers(memrec_t *memrec)
unsigned long len;
spif_char_t buff[9];
- ASSERT(memrec != NULL);
+ ASSERT(!!memrec);
fprintf(LIBAST_DEBUG_FD, "PTR: %lu pointers stored.\n", (unsigned long) memrec->cnt);
fprintf(LIBAST_DEBUG_FD,
"PTR: Pointer | Filename | Line | Address | Size | Offset | 00 01 02 03 04 05 06 07 | ASCII \n");
@@ -375,7 +375,7 @@ memrec_dump_resources(memrec_t *memrec)
unsigned long i, total;
unsigned long len;
- ASSERT(memrec != NULL);
+ ASSERT(!!memrec);
len = memrec->cnt;
fprintf(LIBAST_DEBUG_FD, "RES: %lu resources stored.\n",
(unsigned long) memrec->cnt);
@@ -471,7 +471,7 @@ spifmem_realloc(const spif_charptr_t var, const spif_charptr_t filename, unsigne
#endif
D_MEM(("Variable %s (%10p -> %lu) at %s:%lu\n", var, ptr, (unsigned long) size, NONULL(filename), line));
- if (ptr == NULL) {
+ if (!ptr) {
temp = (void *) spifmem_malloc(filename, line, size);
} else if (size == 0) {
spifmem_free(var, filename, line, ptr);
@@ -878,7 +878,7 @@ spiftool_free_array(void *list, size_t count)
register size_t i;
void **l = (void **) list;
- REQUIRE(list != NULL);
+ REQUIRE(!!list);
if (count == 0) {
count = (size_t) (-1);
diff --git a/src/msgs.c b/src/msgs.c
index 5012e3d..7d54f9a 100644
--- a/src/msgs.c
+++ b/src/msgs.c
@@ -165,7 +165,7 @@ libast_dprintf(const char *format, ...)
ASSERT_RVAL(!SPIF_PTR_ISNULL(format), (int) -1);
REQUIRE_RVAL(!silent, 0);
- REQUIRE_RVAL(libast_program_name != NULL, 0);
+ REQUIRE_RVAL(!!libast_program_name, 0);
va_start(args, format);
n = vfprintf(LIBAST_DEBUG_FD, format, args);
va_end(args);
@@ -194,7 +194,7 @@ libast_print_error(const char *fmt, ...)
ASSERT(!SPIF_PTR_ISNULL(fmt));
REQUIRE(!silent);
- REQUIRE(libast_program_name != NULL);
+ REQUIRE(!!libast_program_name);
va_start(arg_ptr, fmt);
fprintf(stderr, "%s: Error: ", libast_program_name);
vfprintf(stderr, fmt, arg_ptr);
@@ -222,7 +222,7 @@ libast_print_warning(const char *fmt, ...)
ASSERT(!SPIF_PTR_ISNULL(fmt));
REQUIRE(!silent);
- REQUIRE(libast_program_name != NULL);
+ REQUIRE(!!libast_program_name);
va_start(arg_ptr, fmt);
fprintf(stderr, "%s: Warning: ", libast_program_name);
vfprintf(stderr, fmt, arg_ptr);
@@ -249,7 +249,7 @@ libast_fatal_error(const char *fmt, ...)
va_list arg_ptr;
ASSERT(!SPIF_PTR_ISNULL(fmt));
- if ((!silent) && (libast_program_name != NULL)) {
+ if ((!silent) && (libast_program_name)) {
va_start(arg_ptr, fmt);
fprintf(stderr, "%s: FATAL: ", libast_program_name);
vfprintf(stderr, fmt, arg_ptr);
diff --git a/src/options.c b/src/options.c
index afdd123..80ef34d 100644
--- a/src/options.c
+++ b/src/options.c
@@ -257,7 +257,7 @@ find_value_long(spif_charptr_t arg, spif_charptr_t next_arg, spif_charptr_t hase
{
spif_charptr_t val_ptr;
- if ((val_ptr = SPIF_CHARPTR(strchr((char *) arg, '='))) != NULL) {
+ if ((val_ptr = SPIF_CHARPTR(strchr((char *)arg, '=')))) {
val_ptr++;
*hasequal = 1;
} else {
@@ -291,7 +291,7 @@ find_value_short(spif_charptr_t arg, spif_charptr_t next_arg)
if (arg[1]) {
val_ptr = arg + 1;
- } else if (next_arg != NULL) {
+ } else if (next_arg) {
val_ptr = next_arg;
}
D_OPTIONS(("val_ptr == %10.8p \"%s\"\n", val_ptr, NONULL(val_ptr)));
@@ -335,7 +335,7 @@ is_boolean_value(spif_charptr_t val_ptr)
static spif_bool_t
is_valid_option(spif_charptr_t opt)
{
- REQUIRE_RVAL(opt != NULL, FALSE);
+ REQUIRE_RVAL(!!opt, FALSE);
if (*opt != '-') {
return FALSE;
@@ -527,7 +527,7 @@ spifopt_parse(int argc, char *argv[])
spif_charptr_t opt;
REQUIRE(argc > 1);
- REQUIRE(argv != NULL);
+ REQUIRE(!!argv);
/* Process each command line arg one-by-one. */
for (i = 1, opt = SPIF_CHARPTR(argv[1]); i < argc; ) {
@@ -608,7 +608,7 @@ spifopt_parse(int argc, char *argv[])
/* Make sure that options which require a parameter have them. */
if (SPIFOPT_OPT_NEEDS_VALUE(j)) {
- if (val_ptr == NULL) {
+ if (!val_ptr) {
if (islong) {
libast_print_error("long option --%s requires a%s value\n", SPIFOPT_OPT_LONG(j),
(SPIFOPT_OPT_IS_INTEGER(j)
@@ -632,10 +632,10 @@ spifopt_parse(int argc, char *argv[])
continue;
}
/* Also make sure we know what to do with the value. */
- if (SPIFOPT_OPT_VALUE(j) == NULL) {
+ if (!SPIFOPT_OPT_VALUE(j)) {
NEXT_LOOP();
}
- } else if (SPIFOPT_OPT_IS_ABSTRACT(j) && SPIFOPT_OPT_VALUE(j) == NULL) {
+ } else if (SPIFOPT_OPT_IS_ABSTRACT(j) && !SPIFOPT_OPT_VALUE(j)) {
/* Also make sure that abstract options have a function pointer. */
NEXT_LOOP();
}
diff --git a/src/snprintf.c b/src/snprintf.c
index 273f0a1..6ca1a7b 100644
--- a/src/snprintf.c
+++ b/src/snprintf.c
@@ -239,7 +239,7 @@ fmtstr(char *value, int ljust, int len, int zpad, int precision)
int padlen, strlen, i, c; /* amount to pad */
zpad = 0;
- if (value == NULL) {
+ if (!value) {
value = "<NULL>";
}
if (precision > 0) {
@@ -382,7 +382,7 @@ dostr(char *str)
static void
dopr_outch(int c)
{
- if (end == NULL || output < end) {
+ if (!end || output < end) {
*output++ = c;
}
}
diff --git a/src/socket.c b/src/socket.c
index cb8d8e3..3939864 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -651,8 +651,8 @@ spif_url_init_from_ipaddr(spif_url_t self, spif_ipsockaddr_t ipaddr)
do {
tries++;
hinfo = gethostbyaddr((const char *) &(ipaddr->sin_addr), sizeof(ipaddr->sin_addr), AF_INET);
- } while ((tries <= 3) && (hinfo == NULL) && (h_errno == TRY_AGAIN));
- if (hinfo == NULL || hinfo->h_name == NULL) {
+ } while ((tries <= 3) && (!hinfo) && (h_errno == TRY_AGAIN));
+ if (!hinfo || !hinfo->h_name) {
spif_charptr_t buff;
buff = SPIF_CHARPTR(inet_ntoa(ipaddr->sin_addr));
@@ -691,7 +691,7 @@ spif_url_init_from_unixaddr(spif_url_t self, spif_unixsockaddr_t unixaddr)
self->port = (spif_str_t) NULL;
self->query = (spif_str_t) NULL;
- if (unixaddr->sun_path != NULL) {
+ if (unixaddr->sun_path) {
self->path = spif_str_new_from_ptr(SPIF_CHARPTR(unixaddr->sun_path));
} else {
self->path = (spif_str_t) NULL;
@@ -719,13 +719,13 @@ spif_url_get_ipaddr(spif_url_t self)
do {
tries++;
hinfo = gethostbyname((char *) SPIF_STR_STR(hostname));
- } while ((tries <= 3) && (hinfo == NULL) && (h_errno == TRY_AGAIN));
- if (hinfo == NULL) {
+ } while ((tries <= 3) && (!hinfo) && (h_errno == TRY_AGAIN));
+ if (!hinfo) {
libast_print_error("Unable to resolve hostname \"%s\" -- %s\n", SPIF_STR_STR(hostname), hstrerror(h_errno));
return (spif_ipsockaddr_t) NULL;
}
- if (hinfo->h_addr_list == NULL) {
+ if (!hinfo->h_addr_list) {
libast_print_error("Invalid address list returned by gethostbyname()\n");
return (spif_ipsockaddr_t) NULL;
}
@@ -811,19 +811,19 @@ spif_socket_get_proto(spif_socket_t self)
/* IP socket. See if they gave us a protocol name. */
SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET);
proto = getprotobyname((char *) SPIF_STR_STR(proto_str));
- if (proto == NULL) {
+ if (!proto) {
/* If it's not a protocol, it's probably a service. */
serv = getservbyname((char *) SPIF_STR_STR(proto_str), "tcp");
- if (serv == NULL) {
+ if (!serv) {
serv = getservbyname((char *) SPIF_STR_STR(proto_str), "udp");
}
- if (serv != NULL) {
+ if (serv) {
/* If we found one, get the protocol info too. */
proto = getprotobyname(serv->s_proto);
- REQUIRE_RVAL(proto != NULL, FALSE);
+ REQUIRE_RVAL(!!proto, FALSE);
}
}
- if (proto != NULL) {
+ if (proto) {
/* Bingo. Set the flags appropriately. */
self->proto = proto->p_proto;
if (!strcmp(proto->p_name, "tcp")) {
diff --git a/src/str.c b/src/str.c
index 83b4ac3..c3ac4c7 100644
--- a/src/str.c
+++ b/src/str.c
@@ -230,8 +230,7 @@ spif_str_init_from_fp(spif_str_t self, FILE *fp)
self->s = (spif_charptr_t) MALLOC(self->size);
for (p = self->s; fgets((char *)p, buff_inc, fp); p += buff_inc) {
- if ((end = (spif_charptr_t)
- strchr((const char *)p, '\n')) == NULL) {
+ if (!(end = (spif_charptr_t)strchr((const char *)p, '\n'))) {
self->size += buff_inc;
self->s = (spif_charptr_t) REALLOC(self->s, self->size);
} else {
diff --git a/src/strings.c b/src/strings.c
index 1195861..c100462 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -318,8 +318,8 @@ spiftool_regexp_match_r(register const spif_charptr_t str, register const spif_c
register int result;
char errbuf[256];
- ASSERT_RVAL(rexp != NULL, FALSE);
- if (*rexp == NULL) {
+ ASSERT_RVAL(!!rexp, FALSE);
+ if (!*rexp) {
*rexp = (regex_t *) MALLOC(sizeof(regex_t));
}
@@ -342,7 +342,7 @@ spiftool_regexp_match_r(register const spif_charptr_t str, register const spif_c
}
#endif
-#define IS_DELIM(c) ((delim != NULL) ? (strchr((char *) delim, (c)) != NULL) : (isspace(c)))
+#define IS_DELIM(c) ((delim) ? (strchr((char *)delim, (c))) : (isspace(c)))
#define IS_QUOTE(c) (quote && quote == (c))
spif_charptr_t *
@@ -355,9 +355,9 @@ spiftool_split(const spif_charptr_t delim, const spif_charptr_t str)
unsigned short cnt = 0;
unsigned long len;
- REQUIRE_RVAL(str != NULL, (spif_charptr_t *) NULL);
+ REQUIRE_RVAL(!!str, (spif_charptr_t *) NULL);
- if ((slist = (spif_charptr_t *) MALLOC(sizeof(spif_charptr_t))) == NULL) {
+ if (!(slist = (spif_charptr_t *)MALLOC(sizeof(spif_charptr_t)))) {
libast_print_error("split(): Unable to allocate memory -- %s\n", strerror(errno));
return ((spif_charptr_t *) NULL);
}
@@ -370,7 +370,7 @@ spiftool_split(const spif_charptr_t delim, const spif_charptr_t str)
for (; *pstr; cnt++) {
/* First, resize the list to two bigger than our count. Why two?
One for the string we're about to do, and one for a trailing NULL. */
- if ((slist = (spif_charptr_t *) REALLOC(slist, sizeof(spif_charptr_t) * (cnt + 2))) == NULL) {
+ if (!(slist = (spif_charptr_t *)REALLOC(slist, sizeof(spif_charptr_t) * (cnt + 2)))) {
libast_print_error("split(): Unable to allocate memory -- %s\n", strerror(errno));
return ((spif_charptr_t *) NULL);
}
@@ -378,7 +378,7 @@ spiftool_split(const spif_charptr_t delim, const spif_charptr_t str)
/* The string we're about to create can't possibly be larger than the remainder
of the string we have yet to parse, so allocate that much space to start. */
len = strlen((char *) pstr) + 1;
- if ((slist[cnt] = (spif_charptr_t) MALLOC(len)) == NULL) {
+ if (!(slist[cnt] = (spif_charptr_t)MALLOC(len))) {
libast_print_error("split(): Unable to allocate memory -- %s.\n", strerror(errno));
return ((spif_charptr_t *) NULL);
}
@@ -446,7 +446,7 @@ spiftool_join(spif_charptr_t sep, spif_charptr_t *slist)
ASSERT_RVAL(slist != (spif_ptr_t) NULL, (spif_ptr_t) NULL);
REQUIRE_RVAL(*slist != (spif_ptr_t) NULL, (spif_ptr_t) NULL);
- if (sep == NULL) {
+ if (!sep) {
sep = SPIF_CHARPTR("");
}
slen = strlen((char *) sep);
@@ -478,7 +478,7 @@ spiftool_get_word(unsigned long index, const spif_charptr_t str)
ASSERT_RVAL(str != (spif_ptr_t) NULL, (spif_ptr_t) NULL);
k = strlen((char *) str) + 1;
- if ((tmpstr = (spif_charptr_t) MALLOC(k)) == NULL) {
+ if (!(tmpstr = (spif_charptr_t)MALLOC(k))) {
libast_print_error("get_word(%lu, %s): Unable to allocate memory -- %s.\n", index, str, strerror(errno));
return ((spif_charptr_t) NULL);
}
@@ -594,7 +594,7 @@ spiftool_chomp(spif_charptr_t s)
{
register spif_charptr_t front, back;
- ASSERT_RVAL(s != NULL, NULL);
+ ASSERT_RVAL(!!s, NULL);
REQUIRE_RVAL(*s, s);
for (front = s; *front && isspace(*front); front++);
diff --git a/src/tok.c b/src/tok.c
index 7363d1d..a84c760 100644
--- a/src/tok.c
+++ b/src/tok.c
@@ -275,7 +275,7 @@ spif_tok_type(spif_tok_t self)
return SPIF_OBJ_CLASSNAME(self);
}
-#define IS_DELIM(c) ((delim != NULL) ? (strchr(delim, (c)) != NULL) : (isspace(c)))
+#define IS_DELIM(c) ((delim) ? (strchr(delim, (c))) : (isspace(c)))
#define IS_QUOTE(c) (quote && quote == (c))
spif_bool_t
diff --git a/src/url.c b/src/url.c
index 09bf84a..70f9b00 100644
--- a/src/url.c
+++ b/src/url.c
@@ -262,7 +262,7 @@ spif_url_parse(spif_url_t self)
/* Check for "proto:" at the beginning. */
pend = SPIF_CHARPTR(strchr((char *) s, ':'));
- if (pend != NULL) {
+ if (pend) {
for (; pstr < pend; pstr++) {
if (!isalnum(*pstr)) {
break;
@@ -284,16 +284,16 @@ spif_url_parse(spif_url_t self)
/* Knock out the path and query if they're there. */
pend = SPIF_CHARPTR(strchr((char *) pstr, '/'));
- if (pend != NULL) {
+ if (pend) {
spif_charptr_t tmp = SPIF_CHARPTR(strchr((char *) pend, '?'));
- if (tmp != NULL) {
+ if (tmp) {
self->query = spif_str_new_from_ptr(tmp + 1);
self->path = spif_str_new_from_buff(pend, tmp - pend);
} else {
self->path = spif_str_new_from_ptr(pend);
}
- } else if ((pend = SPIF_CHARPTR(strchr((char *) pstr, '?'))) != NULL) {
+ } else if ((pend = SPIF_CHARPTR(strchr((char *)pstr, '?')))) {
self->query = spif_str_new_from_ptr(pend + 1);
} else {
for (pend = pstr; *pend; pend++);
@@ -302,10 +302,10 @@ spif_url_parse(spif_url_t self)
/* Check for an @ sign, which would mean we have auth info. */
ptmp = SPIF_CHARPTR(strchr((char *) pstr, '@'));
- if ((ptmp != NULL) && (ptmp < pend)) {
+ if ((ptmp) && (ptmp < pend)) {
spif_charptr_t tmp = SPIF_CHARPTR(strchr((char *) pstr, ':'));
- if ((tmp != NULL) && (tmp < ptmp)) {
+ if ((tmp) && (tmp < ptmp)) {
/* Both username and password. */
self->user = spif_str_new_from_buff(pstr, tmp - pstr);
self->passwd = spif_str_new_from_buff((tmp + 1), ptmp - tmp - 1);
@@ -317,7 +317,7 @@ spif_url_parse(spif_url_t self)
/* All that remains now between pstr and pend is host and maybe port. */
ptmp = SPIF_CHARPTR(strchr((char *) pstr, ':'));
- if ((ptmp != NULL) && (ptmp < pend)) {
+ if ((ptmp) && (ptmp < pend)) {
self->host = spif_str_new_from_buff(pstr, ptmp - pstr);
self->port = spif_str_new_from_buff((ptmp + 1), pend - ptmp - 1);
} else if (pstr != pend) {
@@ -330,18 +330,18 @@ spif_url_parse(spif_url_t self)
spif_servinfo_t serv;
proto = getprotobyname((char *) SPIF_STR_STR(self->proto));
- if (proto == NULL) {
+ if (!proto) {
/* If it's not a protocol, it's probably a service. */
serv = getservbyname((char *) SPIF_STR_STR(self->proto), "tcp");
- if (serv == NULL) {
+ if (!serv) {
serv = getservbyname((char *) SPIF_STR_STR(self->proto), "udp");
}
- if (serv != NULL) {
+ if (serv) {
proto = getprotobyname(serv->s_proto);
- REQUIRE_RVAL(proto != NULL, FALSE);
+ REQUIRE_RVAL(!!proto, FALSE);
}
}
- if (proto != NULL) {
+ if (proto) {
spif_char_t buff[32];
snprintf((char *) buff, sizeof(buff), "%d", ntohs(serv->s_port));
diff --git a/src/ustr.c b/src/ustr.c
index 35c80ab..4fb8e91 100644
--- a/src/ustr.c
+++ b/src/ustr.c
@@ -230,8 +230,7 @@ spif_ustr_init_from_fp(spif_ustr_t self, FILE *fp)
self->s = (spif_charptr_t) MALLOC(self->size);
for (p = self->s; fgets((char *)p, buff_inc, fp); p += buff_inc) {
- if ((end = (spif_charptr_t)
- strchr((const char *)p, '\n')) == NULL) {
+ if (!(end = (spif_charptr_t)strchr((const char *)p, '\n'))) {
self->size += buff_inc;
self->s = (spif_charptr_t) REALLOC(self->s, self->size);
} else {
diff --git a/test/test.c b/test/test.c
index 1fdff41..e73fbb7 100644
--- a/test/test.c
+++ b/test/test.c
@@ -161,8 +161,8 @@ test_strings(void)
s3 = spiftool_substr(NULL, 0, 0);
s4 = spiftool_substr(SPIF_CHARPTR("what the heck"), -5, 42);
TEST_FAIL_IF(strcmp((char *) s1, "ultramicroscopic"));
- TEST_FAIL_IF(s2 != NULL);
- TEST_FAIL_IF(s3 != NULL);
+ TEST_FAIL_IF(!!s2);
+ TEST_FAIL_IF(!!s3);
TEST_FAIL_IF(strcmp((char *) s4, " heck"));
FREE(s1);
FREE(s2);
@@ -327,15 +327,15 @@ test_options(void)
SPIFOPT_FLAGS_SET(SPIFOPT_SETTING_PREPARSE);
spifopt_parse(argc1, argv1);
TEST_FAIL_IF(test_flag_var != 0x10);
- TEST_FAIL_IF(file_var != NULL);
- TEST_FAIL_IF(exec_list != NULL);
+ TEST_FAIL_IF(!!file_var);
+ TEST_FAIL_IF(!!exec_list);
TEST_FAIL_IF(num_var != 0);
TEST_FAIL_IF(geom_var != 0);
spifopt_parse(argc1, argv1);
TEST_FAIL_IF(test_flag_var != 0x13);
- TEST_FAIL_IF(file_var == NULL);
+ TEST_FAIL_IF(!file_var);
TEST_FAIL_IF(strcmp((char *) file_var, "somefile"));
- TEST_FAIL_IF(exec_list == NULL);
+ TEST_FAIL_IF(!exec_list);
TEST_FAIL_IF(num_var != 1);
TEST_FAIL_IF(geom_var != 3);
FREE(file_var);
@@ -348,31 +348,31 @@ test_options(void)
SPIFOPT_FLAGS_SET(SPIFOPT_SETTING_REMOVE_ARGS);
spifopt_parse(argc2, argv2);
TEST_FAIL_IF(strcmp((char *) display, "foo:0"));
- TEST_FAIL_IF(name != NULL);
+ TEST_FAIL_IF(!!name);
TEST_FAIL_IF(strcmp((char *) theme, "mytheme"));
- TEST_FAIL_IF(exec == NULL);
+ TEST_FAIL_IF(!exec);
TEST_FAIL_IF(strcmp((char *) exec[0], "ssh"));
TEST_FAIL_IF(strcmp((char *) exec[1], "foo@bar.com"));
- TEST_FAIL_IF(exec[2] != NULL);
- TEST_FAIL_IF(foo != NULL);
+ TEST_FAIL_IF(!!exec[2]);
+ TEST_FAIL_IF(!!foo);
TEST_FAIL_IF(color != 0);
TEST_FAIL_IF(options != 0x08);
spifopt_parse(argc2, argv2);
TEST_FAIL_IF(strcmp((char *) display, "foo:0"));
TEST_FAIL_IF(strcmp((char *) name, "This is a name"));
TEST_FAIL_IF(strcmp((char *) theme, "mytheme"));
- TEST_FAIL_IF(exec == NULL);
+ TEST_FAIL_IF(!exec);
TEST_FAIL_IF(strcmp((char *) exec[0], "ssh"));
TEST_FAIL_IF(strcmp((char *) exec[1], "foo@bar.com"));
- TEST_FAIL_IF(exec[2] != NULL);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!!exec[2]);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(SPIF_PTR_ISNULL(foo[0]));
TEST_FAIL_IF(strcmp((char *) foo[0], "blah"));
TEST_FAIL_IF(SPIF_PTR_ISNULL(foo[1]));
TEST_FAIL_IF(strcmp((char *) foo[1], "-d"));
TEST_FAIL_IF(SPIF_PTR_ISNULL(foo[2]));
TEST_FAIL_IF(strcmp((char *) foo[2], "eatme"));
- TEST_FAIL_IF(foo[3] != NULL);
+ TEST_FAIL_IF(!!foo[3]);
TEST_FAIL_IF(color != 4);
TEST_FAIL_IF(options != 0x1e);
TEST_FAIL_IF(strcmp(argv2[0], "test"));
@@ -463,7 +463,7 @@ test_str(void)
fp = fdopen(fd, "r");
write(mypipe[1], tmp2, sizeof(tmp2));
close(mypipe[1]);
- TEST_FAIL_IF(fp == NULL);
+ TEST_FAIL_IF(!fp);
teststr = spif_str_new_from_fp(fp);
TEST_FAIL_IF(spif_str_ncmp_with_ptr(teststr, SPIF_CHARPTR("string #1"), 9));
TEST_FAIL_IF(spif_str_get_len(teststr) != 9);
@@ -563,11 +563,11 @@ test_str(void)
TEST_BEGIN("spif_str_substr_to_ptr() function");
teststr = spif_str_new_from_ptr(SPIF_CHARPTR(tmp));
foo = spif_str_substr_to_ptr(teststr, 2, 5);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(strcmp((char *) foo, "is is"));
FREE(foo);
foo = spif_str_substr_to_ptr(teststr, -4, 4);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(strcmp((char *) foo, "test"));
FREE(foo);
spif_str_del(teststr);
@@ -842,7 +842,7 @@ test_mbuff(void)
fp = fdopen(fd, "r");
write(mypipe[1], tmp2, sizeof(tmp2));
close(mypipe[1]);
- TEST_FAIL_IF(fp == NULL);
+ TEST_FAIL_IF(!fp);
testmbuff = spif_mbuff_new_from_fp(fp);
TEST_FAIL_IF(spif_mbuff_cmp_with_ptr(testmbuff, tmp2, sizeof(tmp2)));
TEST_FAIL_IF(spif_mbuff_get_len(testmbuff) != sizeof(tmp2));
@@ -918,11 +918,11 @@ test_mbuff(void)
TEST_BEGIN("spif_mbuff_subbuff_to_ptr() function");
testmbuff = spif_mbuff_new_from_ptr(SPIF_CHARPTR(tmp), strlen(tmp));
foo = spif_mbuff_subbuff_to_ptr(testmbuff, 2, 5);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(memcmp((char *) foo, "is is", 5));
FREE(foo);
foo = spif_mbuff_subbuff_to_ptr(testmbuff, -4, 4);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(memcmp((char *) foo, "test", 5));
FREE(foo);
spif_mbuff_del(testmbuff);
@@ -1057,7 +1057,7 @@ test_ustr(void)
fp = fdopen(fd, "r");
write(mypipe[1], tmp2, sizeof(tmp2));
close(mypipe[1]);
- TEST_FAIL_IF(fp == NULL);
+ TEST_FAIL_IF(!fp);
testustr = spif_ustr_new_from_fp(fp);
TEST_FAIL_IF(spif_ustr_ncmp_with_ptr(testustr, SPIF_CHARPTR("string #1"), 9));
TEST_FAIL_IF(spif_ustr_get_len(testustr) != 9);
@@ -1157,11 +1157,11 @@ test_ustr(void)
TEST_BEGIN("spif_ustr_substr_to_ptr() function");
testustr = spif_ustr_new_from_ptr(SPIF_CHARPTR(tmp));
foo = spif_ustr_substr_to_ptr(testustr, 2, 5);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(strcmp((char *) foo, "is is"));
FREE(foo);
foo = spif_ustr_substr_to_ptr(testustr, -4, 4);
- TEST_FAIL_IF(foo == NULL);
+ TEST_FAIL_IF(!foo);
TEST_FAIL_IF(strcmp((char *) foo, "test"));
FREE(foo);
spif_ustr_del(testustr);