summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2010-08-26 01:34:13 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2010-08-26 01:34:13 +0000
commit1255a914bae562cd9e17d88a52ba7f105f8fddf4 (patch)
tree2b57f3499886106002cea071389c9de827b4f8b8
parent8b96666c7c7dd4fc1b52fdb4b55bbc15ca0c071c (diff)
downloadlibast-1255a914bae562cd9e17d88a52ba7f105f8fddf4.tar.gz
Revert and re-apply badnull patch
Revert previous patch generated by badnull.cocci script, and apply the new one. The main difference is that assert and assert-like functions are not touched anymore. SVN revision: 51650
-rw-r--r--src/conf.c26
-rw-r--r--src/mem.c8
-rw-r--r--src/msgs.c2
-rw-r--r--src/options.c10
-rw-r--r--src/snprintf.c4
-rw-r--r--src/socket.c20
-rw-r--r--src/str.c3
-rw-r--r--src/strings.c14
-rw-r--r--src/tok.c2
-rw-r--r--src/url.c22
-rw-r--r--src/ustr.c3
11 files changed, 56 insertions, 58 deletions
diff --git a/src/conf.c b/src/conf.c
index 1d2e74b..49fe9b2 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -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);
@@ -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));
@@ -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);
@@ -862,7 +862,7 @@ spifconf_parse_line(FILE * fp, spif_charptr_t 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);
@@ -957,8 +957,8 @@ spifconf_parse(spif_charptr_t conf_name, const spif_charptr_t dir, const spif_ch
*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..7304533 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -148,7 +148,7 @@ memrec_add_var(memrec_t *memrec, const spif_charptr_t filename, unsigned long li
ASSERT(memrec != NULL);
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;
@@ -220,7 +220,7 @@ memrec_rem_var(memrec_t *memrec, const spif_charptr_t var, const spif_charptr_t
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;
@@ -259,7 +259,7 @@ memrec_chg_var(memrec_t *memrec, const spif_charptr_t var, const spif_charptr_t
ASSERT(memrec != NULL);
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;
@@ -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);
diff --git a/src/msgs.c b/src/msgs.c
index 5012e3d..ded07fc 100644
--- a/src/msgs.c
+++ b/src/msgs.c
@@ -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..be5faa6 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)));
@@ -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..4385a97 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);
}
}
- 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..cfb66bc 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -319,7 +319,7 @@ spiftool_regexp_match_r(register const spif_charptr_t str, register const spif_c
char errbuf[256];
ASSERT_RVAL(rexp != NULL, FALSE);
- if (*rexp == NULL) {
+ 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 *
@@ -357,7 +357,7 @@ spiftool_split(const spif_charptr_t delim, const spif_charptr_t str)
REQUIRE_RVAL(str != NULL, (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);
}
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..5b5c2a0 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);
}
}
- 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 {