Tweak NULL-pointer checks
Use !p and p when comparing pointers as opposed to explicit checks against NULL. This is generally easier to read.
This commit is contained in:
parent
ec8246bbc6
commit
7fc5856e64
2
cksum.c
2
cksum.c
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
8
sort.c
8
sort.c
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
4
split.c
4
split.c
|
@ -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':
|
||||
|
|
4
uniq.c
4
uniq.c
|
@ -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);
|
||||
|
||||
|
@ -71,7 +71,7 @@ uniqline(char *l)
|
|||
return;
|
||||
}
|
||||
|
||||
if (prevline != NULL) {
|
||||
if (prevline) {
|
||||
if ((prevlinecount == 1 && !dflag) ||
|
||||
(prevlinecount != 1 && !uflag)) {
|
||||
printf(countfmt, prevlinecount);
|
||||
|
|
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
12
uudecode.c
12
uudecode.c
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue
Block a user