Simplify NULL checks.

This commit is contained in:
syb0rg 2014-04-23 19:50:39 -05:00
parent ca3dde98e9
commit 9634d0271f
6 changed files with 28 additions and 30 deletions

View File

@ -255,7 +255,7 @@ do_pidfile(char *pidfile)
#ifndef WINDOWS32
FILE *file;
if ((file = fopen(pidfile, "w")) == NULL) {
if ((file = fopen(pidfile, "w"))) {
syslog(LOG_ERR, "Cannot write pidfile to %s, exiting", pidfile);
err(1, "do_pidfile: Can not write pidfile to %s", pidfile);
} else {

View File

@ -431,7 +431,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
rlen = 0;
if (q != NULL)
if (q)
q->rcode = header->rcode;
switch (qr) {
@ -441,7 +441,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
return -1;
}
if (q != NULL)
if (q)
q->id = id;
/* Read name even if no answer, to give better error message */
@ -451,7 +451,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
readshort(packet, &data, &class);
/* if CHECKLEN okay, then we're sure to have a proper name */
if (q != NULL) {
if (q) {
/* We only need the first char to check it */
q->name[0] = name[0];
q->name[1] = '\0';
@ -577,7 +577,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
}
/* Here type is the answer type (note A->CNAME) */
if (q != NULL)
if (q)
q->type = type;
break;
case QR_QUERY:
@ -593,7 +593,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
readshort(packet, &data, &type);
readshort(packet, &data, &class);
if (q == NULL) {
if (!q) {
rv = 0;
break;
}

View File

@ -173,7 +173,7 @@ main(int argc, char **argv)
#if !defined(BSD) && !defined(__GLIBC__)
__progname = strrchr(argv[0], '/');
if (__progname == NULL)
if (!__progname)
__progname = argv[0];
else
__progname++;
@ -320,9 +320,9 @@ main(int argc, char **argv)
client_set_topdomain(topdomain);
client_set_hostname_maxlen(hostname_maxlen);
if (username != NULL) {
if (username) {
#ifndef WINDOWS32
if ((pw = getpwnam(username)) == NULL) {
if (!(pw = getpwnam(username))) {
warnx("User %s does not exist!\n", username);
usage();
/* NOTREACHED */
@ -331,7 +331,7 @@ main(int argc, char **argv)
}
if (strlen(password) == 0) {
if (NULL != getenv(PASSWORD_ENV_VAR))
if (getenv(PASSWORD_ENV_VAR))
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
else
read_password(password, sizeof(password));
@ -372,13 +372,13 @@ main(int argc, char **argv)
if (foreground == 0)
do_detach();
if (pidfile != NULL)
if (pidfile)
do_pidfile(pidfile);
if (newroot != NULL)
if (newroot)
do_chroot(newroot);
if (username != NULL) {
if (username) {
#ifndef WINDOWS32
gid_t gids[1];
gids[0] = pw->pw_gid;
@ -390,7 +390,7 @@ main(int argc, char **argv)
#endif
}
if (context != NULL)
if (context)
do_setcon(context);
client_tunnel(tun_fd, dns_fd);

View File

@ -415,7 +415,7 @@ save_to_qmem_pingordata(int userid, struct query *q)
size_t cmcsize = sizeof(cmc);
char *cp = strchr(q->name, '.');
if (cp == NULL)
if (!cp)
return; /* illegal hostname; shouldn't happen */
/* We already unpacked in handle_null_request(), but that's
@ -1993,9 +1993,7 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
}
#ifndef WINDOWS32
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == IPPROTO_IP &&
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
@ -2298,7 +2296,7 @@ main(int argc, char **argv)
#if !defined(BSD) && !defined(__GLIBC__)
__progname = strrchr(argv[0], '/');
if (__progname == NULL)
if (!__progname)
__progname = argv[0];
else
__progname++;
@ -2412,9 +2410,9 @@ main(int argc, char **argv)
usage();
}
if (username != NULL) {
if (username) {
#ifndef WINDOWS32
if ((pw = getpwnam(username)) == NULL) {
if (!(pw = getpwnam(username))) {
warnx("User %s does not exist!", username);
usage();
}
@ -2543,7 +2541,7 @@ main(int argc, char **argv)
if (foreground == 0)
do_detach();
if (pidfile != NULL)
if (pidfile)
do_pidfile(pidfile);
#ifdef FREEBSD
@ -2553,11 +2551,11 @@ main(int argc, char **argv)
openlog( __progname, LOG_NDELAY, LOG_DAEMON );
#endif
if (newroot != NULL)
if (newroot)
do_chroot(newroot);
signal(SIGINT, sigint);
if (username != NULL) {
if (username) {
#ifndef WINDOWS32
gid_t gids[1];
gids[0] = pw->pw_gid;
@ -2568,7 +2566,7 @@ main(int argc, char **argv)
#endif
}
if (context != NULL)
if (context)
do_setcon(context);
syslog(LOG_INFO, "started, listening on port %d", port);

View File

@ -89,7 +89,7 @@ open_tun(const char *tun_device)
ifreq.ifr_flags = IFF_TUN;
if (tun_device != NULL) {
if (tun_device) {
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
ifreq.ifr_name[IFNAMSIZ-1] = '\0';
strncpy(if_name, tun_device, sizeof(if_name));
@ -135,7 +135,7 @@ open_tun(const char *tun_device)
int tun_fd;
char tun_name[50];
if (tun_device != NULL) {
if (tun_device) {
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
strncpy(if_name, tun_device, sizeof(if_name));
if_name[sizeof(if_name)-1] = '\0';

View File

@ -27,9 +27,9 @@ get_resolvconf_addr(void)
FILE *fp;
#ifdef ANDROID
fp = popen("getprop net.dns1", "r");
if (fp == NULL)
if (!fp)
err(1, "getprop net.dns1 failed");
if (fgets(buf, sizeof(buf), fp) == NULL)
if (!fgets(buf, sizeof(buf), fp))
err(1, "read getprop net.dns1 failed");
if (sscanf(buf, "%15s", addr) == 1)
rv = addr;
@ -38,7 +38,7 @@ get_resolvconf_addr(void)
rv = NULL;
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
if (!(fp = fopen("/etc/resolv.conf", "r")))
err(1, "/etc/resolv.conf");
while (feof(fp) == 0) {