aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-04-10 19:33:58 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-04-10 19:33:58 +0000
commit513004a23dac3416f8f9c11aaa148bf8606c8617 (patch)
tree6796a0cd32cea8fd5591b7f2c6d10ae7f153ccb9 /lib/libc
parent6e5bbb486cf872ff289d4573cb9d08bf3178b160 (diff)
downloadsrc-513004a23dac3416f8f9c11aaa148bf8606c8617.tar.gz
src-513004a23dac3416f8f9c11aaa148bf8606c8617.zip
libc: replace 0 with NULL for pointers.
While here also cleanup some surrounding code; particularly drop some malloc() casts. Found with devel/coccinelle. Reviewed by: bde (previous version - all new bugs are mine)
Notes
Notes: svn path=/head/; revision=297790
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/db/hash/hash.c2
-rw-r--r--lib/libc/db/hash/hash_buf.c4
-rw-r--r--lib/libc/gen/err.c8
-rw-r--r--lib/libc/gen/getmntinfo.c2
-rw-r--r--lib/libc/gen/opendir.c2
-rw-r--r--lib/libc/gen/tls.c4
-rw-r--r--lib/libc/locale/xlocale_private.h11
-rw-r--r--lib/libc/net/base64.c2
-rw-r--r--lib/libc/net/getifaddrs.c3
-rw-r--r--lib/libc/net/getservent.c4
-rw-r--r--lib/libc/net/rcmd.c2
-rw-r--r--lib/libc/posix1e/acl_support_nfs4.c2
-rw-r--r--lib/libc/resolv/mtctxres.c11
-rw-r--r--lib/libc/resolv/res_init.c4
-rw-r--r--lib/libc/resolv/res_mkupdate.c4
-rw-r--r--lib/libc/rpc/auth_none.c6
-rw-r--r--lib/libc/rpc/clnt_perror.c8
-rw-r--r--lib/libc/rpc/mt_misc.c2
-rw-r--r--lib/libc/rpc/rpcdname.c10
-rw-r--r--lib/libc/softfloat/timesoftfloat.c6
-rw-r--r--lib/libc/uuid/uuid_to_string.c2
-rw-r--r--lib/libc/xdr/xdr_mem.c2
22 files changed, 49 insertions, 52 deletions
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index fc4e50eb0b25..f7b14276000c 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -771,7 +771,7 @@ next_bucket:
if (__big_keydata(hashp, bufp, key, data, 1))
return (ERROR);
} else {
- if (hashp->cpage == 0)
+ if (hashp->cpage == NULL)
return (ERROR);
key->data = (u_char *)hashp->cpage->page + bp[ndx];
key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c
index e79e7b3efcfa..5c62a2c36eaf 100644
--- a/lib/libc/db/hash/hash_buf.c
+++ b/lib/libc/db/hash/hash_buf.c
@@ -245,7 +245,7 @@ newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp)
*/
for (xbp = bp; xbp->ovfl;) {
next_xbp = xbp->ovfl;
- xbp->ovfl = 0;
+ xbp->ovfl = NULL;
xbp = next_xbp;
/* Check that ovfl pointer is up date. */
@@ -350,7 +350,7 @@ __buf_free(HTAB *hashp, int do_free, int to_disk)
void
__reclaim_buf(HTAB *hashp, BUFHEAD *bp)
{
- bp->ovfl = 0;
+ bp->ovfl = NULL;
bp->addr = 0;
bp->flags = 0;
BUF_REMOVE(bp);
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index a536e5af8736..3b32c3d61528 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -96,7 +96,7 @@ errc(int eval, int code, const char *fmt, ...)
void
verrc(int eval, int code, const char *fmt, va_list ap)
{
- if (err_file == 0)
+ if (err_file == NULL)
err_set_file((FILE *)0);
fprintf(err_file, "%s: ", _getprogname());
if (fmt != NULL) {
@@ -121,7 +121,7 @@ errx(int eval, const char *fmt, ...)
void
verrx(int eval, const char *fmt, va_list ap)
{
- if (err_file == 0)
+ if (err_file == NULL)
err_set_file((FILE *)0);
fprintf(err_file, "%s: ", _getprogname());
if (fmt != NULL)
@@ -161,7 +161,7 @@ warnc(int code, const char *fmt, ...)
void
vwarnc(int code, const char *fmt, va_list ap)
{
- if (err_file == 0)
+ if (err_file == NULL)
err_set_file((FILE *)0);
fprintf(err_file, "%s: ", _getprogname());
if (fmt != NULL) {
@@ -183,7 +183,7 @@ warnx(const char *fmt, ...)
void
vwarnx(const char *fmt, va_list ap)
{
- if (err_file == 0)
+ if (err_file == NULL)
err_set_file((FILE *)0);
fprintf(err_file, "%s: ", _getprogname());
if (fmt != NULL)
diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c
index 99f82aa8fc61..606fea73fbc1 100644
--- a/lib/libc/gen/getmntinfo.c
+++ b/lib/libc/gen/getmntinfo.c
@@ -56,7 +56,7 @@ getmntinfo(struct statfs **mntbufp, int flags)
if (mntbuf)
free(mntbuf);
bufsize = (mntsize + 1) * sizeof(struct statfs);
- if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0)
+ if ((mntbuf = malloc(bufsize)) == NULL)
return (0);
if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
return (0);
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 54928e73d60c..bf4dea3ffc83 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -209,7 +209,7 @@ _filldir(DIR *dirp, bool use_current_pos)
* On the second pass, save pointers to each one.
* Then sort the pointers and remove duplicate names.
*/
- for (dpv = 0;;) {
+ for (dpv = NULL;;) {
n = 0;
ddptr = buf;
while (ddptr < ddeptr) {
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 793205530502..dd1e7dfac77f 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -285,7 +285,7 @@ _init_tls(void)
while (*sp++ != 0)
;
aux = (Elf_Auxinfo *) sp;
- phdr = 0;
+ phdr = NULL;
phent = phnum = 0;
for (auxp = aux; auxp->a_type != AT_NULL; auxp++) {
switch (auxp->a_type) {
@@ -302,7 +302,7 @@ _init_tls(void)
break;
}
}
- if (phdr == 0 || phent != sizeof(Elf_Phdr) || phnum == 0)
+ if (phdr == NULL || phent != sizeof(Elf_Phdr) || phnum == 0)
return;
for (i = 0; (unsigned) i < phnum; i++) {
diff --git a/lib/libc/locale/xlocale_private.h b/lib/libc/locale/xlocale_private.h
index 502b5486e684..77b9ff4ee44f 100644
--- a/lib/libc/locale/xlocale_private.h
+++ b/lib/libc/locale/xlocale_private.h
@@ -155,12 +155,11 @@ __attribute__((unused)) static void
xlocale_release(void *val)
{
struct xlocale_refcounted *obj = val;
- long count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1;
- if (count < 0) {
- if (0 != obj->destructor) {
- obj->destructor(obj);
- }
- }
+ long count;
+
+ count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1;
+ if (count < 0 && obj->destructor != NULL)
+ obj->destructor(obj);
}
/**
diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c
index 8a9c59e3142d..2c4cfe3695c7 100644
--- a/lib/libc/net/base64.c
+++ b/lib/libc/net/base64.c
@@ -210,7 +210,7 @@ b64_pton(const char *src, u_char *target, size_t targsize)
break;
pos = strchr(Base64, ch);
- if (pos == 0) /* A non-base64 character. */
+ if (pos == NULL) /* A non-base64 character. */
return (-1);
switch (state) {
diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c
index f8633d5b959a..4c04e9ef0591 100644
--- a/lib/libc/net/getifaddrs.c
+++ b/lib/libc/net/getifaddrs.c
@@ -85,7 +85,7 @@ getifaddrs(struct ifaddrs **pif)
size_t needed;
char *buf;
char *next;
- struct ifaddrs *cif = 0;
+ struct ifaddrs *cif;
char *p, *p0;
struct rt_msghdr *rtm;
struct if_msghdrl *ifm;
@@ -214,6 +214,7 @@ getifaddrs(struct ifaddrs **pif)
ift = ifa;
idx = 0;
+ cif = NULL;
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)(void *)next;
if (rtm->rtm_version != RTM_VERSION)
diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c
index 6a68ef508d58..45a5355245bb 100644
--- a/lib/libc/net/getservent.c
+++ b/lib/libc/net/getservent.c
@@ -406,14 +406,14 @@ files_servent(void *retval, void *mdata, va_list ap)
continue;
gotname:
- if (proto == 0 || strcmp(serv->s_proto, proto) == 0)
+ if (proto == NULL || strcmp(serv->s_proto, proto) == 0)
rv = NS_SUCCESS;
break;
case nss_lt_id:
if (port != serv->s_port)
continue;
- if (proto == 0 || strcmp(serv->s_proto, proto) == 0)
+ if (proto == NULL || strcmp(serv->s_proto, proto) == 0)
rv = NS_SUCCESS;
break;
case nss_lt_all:
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index c7ca87066c93..7b92f0816261 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -207,7 +207,7 @@ rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser,
}
}
lport--;
- if (fd2p == 0) {
+ if (fd2p == NULL) {
_write(s, "", 1);
lport = 0;
} else {
diff --git a/lib/libc/posix1e/acl_support_nfs4.c b/lib/libc/posix1e/acl_support_nfs4.c
index 1eece989ad3f..7dd7f04daaf3 100644
--- a/lib/libc/posix1e/acl_support_nfs4.c
+++ b/lib/libc/posix1e/acl_support_nfs4.c
@@ -81,7 +81,7 @@ static const char *
format_flag(uint32_t *var, const struct flagnames_struct *flags)
{
- for (; flags->name != 0; flags++) {
+ for (; flags->name != NULL; flags++) {
if ((flags->flag & *var) == 0)
continue;
diff --git a/lib/libc/resolv/mtctxres.c b/lib/libc/resolv/mtctxres.c
index f02a7f50281a..c2aea381761d 100644
--- a/lib/libc/resolv/mtctxres.c
+++ b/lib/libc/resolv/mtctxres.c
@@ -75,7 +75,7 @@ __res_init_ctx(void) {
return (0);
}
- if ((mt = malloc(sizeof (mtctxres_t))) == 0) {
+ if ((mt = malloc(sizeof(mtctxres_t))) == NULL) {
errno = ENOMEM;
return (-1);
}
@@ -94,10 +94,7 @@ __res_init_ctx(void) {
static void
__res_destroy_ctx(void *value) {
- mtctxres_t *mt = (mtctxres_t *)value;
-
- if (mt != 0)
- free(mt);
+ free(value);
}
#endif
@@ -130,9 +127,9 @@ ___mtctxres(void) {
* that fails return a global context.
*/
if (mt_key_initialized) {
- if (((mt = pthread_getspecific(key)) != 0) ||
+ if (((mt = pthread_getspecific(key)) != NULL) ||
(__res_init_ctx() == 0 &&
- (mt = pthread_getspecific(key)) != 0)) {
+ (mt = pthread_getspecific(key)) != NULL)) {
return (mt);
}
}
diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c
index 8832342b1059..98563222d1a1 100644
--- a/lib/libc/resolv/res_init.c
+++ b/lib/libc/resolv/res_init.c
@@ -315,7 +315,7 @@ __res_vinit(res_state statp, int preinit) {
while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
cp++;
*cp = '\0';
- *pp++ = 0;
+ *pp++ = NULL;
}
#define MATCH(line, name) \
@@ -391,7 +391,7 @@ __res_vinit(res_state statp, int preinit) {
while (*cp != '\0' && *cp != ' ' && *cp != '\t')
cp++;
*cp = '\0';
- *pp++ = 0;
+ *pp++ = NULL;
havesearch = 1;
continue;
}
diff --git a/lib/libc/resolv/res_mkupdate.c b/lib/libc/resolv/res_mkupdate.c
index c076c1e588c8..3ebb24238d22 100644
--- a/lib/libc/resolv/res_mkupdate.c
+++ b/lib/libc/resolv/res_mkupdate.c
@@ -1175,7 +1175,7 @@ res_protocolname(int num) {
if (protolist == (struct valuelist *)0)
res_buildprotolist();
pp = cgetprotobynumber(num);
- if (pp == 0) {
+ if (pp == NULL) {
(void) sprintf(number, "%d", num);
return (number);
}
@@ -1190,7 +1190,7 @@ res_servicename(u_int16_t port, const char *proto) { /*%< Host byte order. */
if (servicelist == (struct valuelist *)0)
res_buildservicelist();
ss = cgetservbyport(htons(port), proto);
- if (ss == 0) {
+ if (ss == NULL) {
(void) sprintf(number, "%d", port);
return (number);
}
diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c
index 0b846ebc9b18..32bebebf339d 100644
--- a/lib/libc/rpc/auth_none.c
+++ b/lib/libc/rpc/auth_none.c
@@ -83,9 +83,9 @@ authnone_create(void)
XDR *xdrs;
mutex_lock(&authnone_lock);
- if (ap == 0) {
- ap = (struct authnone_private *)calloc(1, sizeof (*ap));
- if (ap == 0) {
+ if (ap == NULL) {
+ ap = calloc(1, sizeof (*ap));
+ if (ap == NULL) {
mutex_unlock(&authnone_lock);
return (0);
}
diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c
index 15d72803df71..d674fbb3847f 100644
--- a/lib/libc/rpc/clnt_perror.c
+++ b/lib/libc/rpc/clnt_perror.c
@@ -64,8 +64,8 @@ static char *
_buf(void)
{
- if (buf == 0)
- buf = (char *)malloc(CLNT_PERROR_BUFLEN);
+ if (buf == NULL)
+ buf = malloc(CLNT_PERROR_BUFLEN);
return (buf);
}
@@ -85,7 +85,7 @@ clnt_sperror(CLIENT *rpch, const char *s)
assert(s != NULL);
str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
- if (str == 0)
+ if (str == NULL)
return (0);
len = CLNT_PERROR_BUFLEN;
strstart = str;
@@ -240,7 +240,7 @@ clnt_spcreateerror(const char *s)
assert(s != NULL);
str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
- if (str == 0)
+ if (str == NULL)
return(0);
len = CLNT_PERROR_BUFLEN;
i = snprintf(str, len, "%s: ", s);
diff --git a/lib/libc/rpc/mt_misc.c b/lib/libc/rpc/mt_misc.c
index 0ec4d8a8b79d..a1b8057bef80 100644
--- a/lib/libc/rpc/mt_misc.c
+++ b/lib/libc/rpc/mt_misc.c
@@ -95,7 +95,7 @@ rce_key_init(void)
struct rpc_createerr *
__rpc_createerr(void)
{
- struct rpc_createerr *rce_addr = 0;
+ struct rpc_createerr *rce_addr = NULL;
if (thr_main())
return (&rpc_createerr);
diff --git a/lib/libc/rpc/rpcdname.c b/lib/libc/rpc/rpcdname.c
index f214b2122d5d..08b5d7d49fc5 100644
--- a/lib/libc/rpc/rpcdname.c
+++ b/lib/libc/rpc/rpcdname.c
@@ -43,20 +43,20 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include "un-namespace.h"
-static char *default_domain = 0;
+static char *default_domain;
static char *
get_default_domain(void)
{
char temp[256];
- if (default_domain)
+ if (default_domain != NULL)
return (default_domain);
if (getdomainname(temp, sizeof(temp)) < 0)
return (0);
if ((int) strlen(temp) > 0) {
- default_domain = (char *)malloc((strlen(temp)+(unsigned)1));
- if (default_domain == 0)
+ default_domain = malloc((strlen(temp) + (unsigned)1));
+ if (default_domain == NULL)
return (0);
(void) strcpy(default_domain, temp);
return (default_domain);
@@ -73,7 +73,7 @@ get_default_domain(void)
int
__rpc_get_default_domain(char **domain)
{
- if ((*domain = get_default_domain()) != 0)
+ if ((*domain = get_default_domain()) != NULL)
return (0);
return (-1);
}
diff --git a/lib/libc/softfloat/timesoftfloat.c b/lib/libc/softfloat/timesoftfloat.c
index 98b6ba2eb3b7..b97c8b0f0d00 100644
--- a/lib/libc/softfloat/timesoftfloat.c
+++ b/lib/libc/softfloat/timesoftfloat.c
@@ -2068,14 +2068,14 @@ static void
roundingPrecisionName = "80";
}
else {
- roundingPrecisionName = 0;
+ roundingPrecisionName = NULL;
}
#ifdef FLOATX80
floatx80_rounding_precision = roundingPrecision;
#endif
switch ( roundingMode ) {
case 0:
- roundingModeName = 0;
+ roundingModeName = NULL;
roundingCode = float_round_nearest_even;
break;
case ROUND_NEAREST_EVEN:
@@ -2098,7 +2098,7 @@ static void
float_rounding_mode = roundingCode;
switch ( tininessMode ) {
case 0:
- tininessModeName = 0;
+ tininessModeName = NULL;
tininessCode = float_tininess_after_rounding;
break;
case TININESS_BEFORE_ROUNDING:
diff --git a/lib/libc/uuid/uuid_to_string.c b/lib/libc/uuid/uuid_to_string.c
index f816391f2a4f..35f8581bfe00 100644
--- a/lib/libc/uuid/uuid_to_string.c
+++ b/lib/libc/uuid/uuid_to_string.c
@@ -49,7 +49,7 @@ uuid_to_string(const uuid_t *u, char **s, uint32_t *status)
*status = uuid_s_ok;
/* Why allow a NULL-pointer here? */
- if (s == 0)
+ if (s == NULL)
return;
if (u == NULL) {
diff --git a/lib/libc/xdr/xdr_mem.c b/lib/libc/xdr/xdr_mem.c
index 0455a5a2a7e5..ecefb2ec38db 100644
--- a/lib/libc/xdr/xdr_mem.c
+++ b/lib/libc/xdr/xdr_mem.c
@@ -215,7 +215,7 @@ xdrmem_setpos(XDR *xdrs, u_int pos)
static int32_t *
xdrmem_inline_aligned(XDR *xdrs, u_int len)
{
- int32_t *buf = 0;
+ int32_t *buf = NULL;
if (xdrs->x_handy >= len) {
xdrs->x_handy -= len;