[hackers] [sbase] Tweak NULL-pointer checks || FRIGN
commit 7fc5856e6453fc60d73150cda10196b932adddd5
Author: FRIGN <dev_AT_frign.de>
Date: Thu Nov 13 22:16:29 2014 +0100
Tweak NULL-pointer checks
Use !p and p when comparing pointers as opposed to explicit
checks against NULL. This is generally easier to read.
diff --git a/cksum.c b/cksum.c
index 9e914ec..9867796 100644
--- a/cksum.c
+++ b/cksum.c
_AT_@ -114,7 +114,7 @@ cksum(FILE *fp, const char *s)
ck = (ck << 8) ^ crctab[(ck >> 24) ^ (i & 0xFF)];
printf("%"PRIu32" %lu", ~ck, (unsigned long)len);
- if (s != NULL)
+ if (s)
printf(" %s", s);
putchar('\n');
}
diff --git a/readlink.c b/readlink.c
index 2d6cc94..10b7160 100644
--- a/readlink.c
+++ b/readlink.c
_AT_@ -43,7 +43,7 @@ main(int argc, char *argv[])
return 1;
if (fflag) {
- if (realpath(argv[0], buf) == NULL)
+ if (!realpath(argv[0], buf))
exit(1);
} else {
if ((n = readlink(argv[0], buf, sizeof(buf) - 1)) < 0)
diff --git a/sort.c b/sort.c
index 5513442..ebe0d82 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -238,12 +238,12 @@ skipblank(char *s)
static char *
nextcol(char *s)
{
- if (fieldsep == NULL) {
+ if (!fieldsep) {
s = skipblank(s);
while(*s && !isblank(*s))
s++;
} else {
- if (strchr(s, *fieldsep) == NULL)
+ if (!strchr(s, *fieldsep))
s = strchr(s, '\0');
else
s = strchr(s, *fieldsep) + 1;
_AT_@ -274,11 +274,11 @@ columns(char *line, const struct keydef *kd)
else
end = nextcol(end);
} else {
- if ((end = strchr(line, '\n')) == NULL)
+ if (!(end = strchr(line, '\n')))
end = strchr(line, '\0');
}
- if ((res = strndup(start, end - start)) == NULL)
+ if (!(res = strndup(start, end - start)))
enprintf(2, "strndup:");
return res;
}
diff --git a/split.c b/split.c
index 22f5029..6bced97 100644
--- a/split.c
+++ b/split.c
_AT_@ -36,11 +36,11 @@ main(int argc, char *argv[])
case 'b':
always = 1;
tmp = ARGF();
- if (tmp == NULL)
+ if (!tmp)
break;
size = strtoull(tmp, &end, 10);
- if (*end == '\0')
+ if (!*end)
break;
switch (toupper((int)*end)) {
case 'K':
diff --git a/uniq.c b/uniq.c
index 7d4caba..f07c40a 100644
--- a/uniq.c
+++ b/uniq.c
_AT_@ -62,7 +62,7 @@ main(int argc, char *argv[])
static void
uniqline(char *l)
{
- int linesequel = ((l == NULL) || (prevline == NULL))
+ int linesequel = (!l || !prevline)
? l == prevline
: !strcmp(l, prevline);
_AT_@ -71,7 +71,7 @@ uniqline(char *l)
return;
}
- if (prevline != NULL) {
+ if (prevline) {
if ((prevlinecount == 1 && !dflag) ||
(prevlinecount != 1 && !uflag)) {
printf(countfmt, prevlinecount);
diff --git a/util/crypt.c b/util/crypt.c
index cbdf2df..c331cf4 100644
--- a/util/crypt.c
+++ b/util/crypt.c
_AT_@ -46,7 +46,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = 0;
size_t bufsiz = 0;
- if (sumfile == NULL)
+ if (!sumfile)
cfp = stdin;
else if (!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile);
_AT_@ -81,7 +81,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
}
fclose(fp);
}
- if (sumfile != NULL)
+ if (sumfile)
fclose(cfp);
free(line);
if (formatsucks > 0) {
_AT_@ -111,7 +111,7 @@ cryptmain(int argc, char *argv[],
mdprint(md, "<stdin>", sz);
} else {
for (; argc > 0; argc--) {
- if ((fp = fopen(*argv, "r")) == NULL) {
+ if (!(fp = fopen(*argv, "r"))) {
weprintf("fopen %s:", *argv);
ret = 1;
continue;
diff --git a/util/getlines.c b/util/getlines.c
index a766ba4..ee9457f 100644
--- a/util/getlines.c
+++ b/util/getlines.c
_AT_@ -17,7 +17,7 @@ getlines(FILE *fp, struct linebuf *b)
if (++b->nlines > b->capacity) {
b->capacity += 512;
nline = realloc(b->lines, b->capacity * sizeof(*b->lines));
- if (nline == NULL)
+ if (!nline)
eprintf("realloc:");
b->lines = nline;
}
diff --git a/uudecode.c b/uudecode.c
index 3ad4fed..09b5d63 100644
--- a/uudecode.c
+++ b/uudecode.c
_AT_@ -40,14 +40,14 @@ main(int argc, char *argv[])
if (argc == 0) {
parseheader(stdin, "<stdin>", "begin ", &mode, &fname);
- if ((nfp = parsefile(fname)) == NULL)
+ if (!(nfp = parsefile(fname)))
eprintf("fopen %s:", fname);
uudecode(stdin, nfp);
} else {
- if ((fp = fopen(argv[0], "r")) == NULL)
+ if (!(fp = fopen(argv[0], "r")))
eprintf("fopen %s:", argv[0]);
parseheader(fp, argv[0], "begin ", &mode, &fname);
- if ((nfp = parsefile(fname)) == NULL)
+ if (!(nfp = parsefile(fname)))
eprintf("fopen %s:", fname);
uudecode(fp, nfp);
}
_AT_@ -93,18 +93,18 @@ parseheader(FILE *fp, const char *s, const char *header, mode_t *mode, char **fn
char *p, *q;
size_t n;
- if (fgets(bufs, sizeof(bufs), fp) == NULL)
+ if (!fgets(bufs, sizeof(bufs), fp))
if (ferror(fp))
eprintf("%s: read error:", s);
if (bufs[0] == '\0' || feof(fp))
eprintf("empty or nil header string\n");
- if ((p = strchr(bufs, '\n')) == NULL)
+ if (!(p = strchr(bufs, '\n')))
eprintf("header string too long or non-newline terminated file\n");
p = bufs;
if (strncmp(bufs, header, strlen(header)) != 0)
eprintf("malformed header prefix\n");
p += strlen(header);
- if ((q = strchr(p, ' ')) == NULL)
+ if (!(q = strchr(p, ' ')))
eprintf("malformed mode string in header\n");
*q++ = '\0';
/* now mode should be null terminated, q points to fname */
Received on Fri Nov 14 2014 - 11:54:33 CET
This archive was generated by hypermail 2.3.0
: Fri Nov 14 2014 - 12:00:14 CET