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)];
|
ck = (ck << 8) ^ crctab[(ck >> 24) ^ (i & 0xFF)];
|
||||||
|
|
||||||
printf("%"PRIu32" %lu", ~ck, (unsigned long)len);
|
printf("%"PRIu32" %lu", ~ck, (unsigned long)len);
|
||||||
if (s != NULL)
|
if (s)
|
||||||
printf(" %s", s);
|
printf(" %s", s);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (fflag) {
|
if (fflag) {
|
||||||
if (realpath(argv[0], buf) == NULL)
|
if (!realpath(argv[0], buf))
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
if ((n = readlink(argv[0], buf, sizeof(buf) - 1)) < 0)
|
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 *
|
static char *
|
||||||
nextcol(char *s)
|
nextcol(char *s)
|
||||||
{
|
{
|
||||||
if (fieldsep == NULL) {
|
if (!fieldsep) {
|
||||||
s = skipblank(s);
|
s = skipblank(s);
|
||||||
while(*s && !isblank(*s))
|
while(*s && !isblank(*s))
|
||||||
s++;
|
s++;
|
||||||
} else {
|
} else {
|
||||||
if (strchr(s, *fieldsep) == NULL)
|
if (!strchr(s, *fieldsep))
|
||||||
s = strchr(s, '\0');
|
s = strchr(s, '\0');
|
||||||
else
|
else
|
||||||
s = strchr(s, *fieldsep) + 1;
|
s = strchr(s, *fieldsep) + 1;
|
||||||
@ -274,11 +274,11 @@ columns(char *line, const struct keydef *kd)
|
|||||||
else
|
else
|
||||||
end = nextcol(end);
|
end = nextcol(end);
|
||||||
} else {
|
} else {
|
||||||
if ((end = strchr(line, '\n')) == NULL)
|
if (!(end = strchr(line, '\n')))
|
||||||
end = strchr(line, '\0');
|
end = strchr(line, '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = strndup(start, end - start)) == NULL)
|
if (!(res = strndup(start, end - start)))
|
||||||
enprintf(2, "strndup:");
|
enprintf(2, "strndup:");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
4
split.c
4
split.c
@ -36,11 +36,11 @@ main(int argc, char *argv[])
|
|||||||
case 'b':
|
case 'b':
|
||||||
always = 1;
|
always = 1;
|
||||||
tmp = ARGF();
|
tmp = ARGF();
|
||||||
if (tmp == NULL)
|
if (!tmp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
size = strtoull(tmp, &end, 10);
|
size = strtoull(tmp, &end, 10);
|
||||||
if (*end == '\0')
|
if (!*end)
|
||||||
break;
|
break;
|
||||||
switch (toupper((int)*end)) {
|
switch (toupper((int)*end)) {
|
||||||
case 'K':
|
case 'K':
|
||||||
|
4
uniq.c
4
uniq.c
@ -62,7 +62,7 @@ main(int argc, char *argv[])
|
|||||||
static void
|
static void
|
||||||
uniqline(char *l)
|
uniqline(char *l)
|
||||||
{
|
{
|
||||||
int linesequel = ((l == NULL) || (prevline == NULL))
|
int linesequel = (!l || !prevline)
|
||||||
? l == prevline
|
? l == prevline
|
||||||
: !strcmp(l, prevline);
|
: !strcmp(l, prevline);
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ uniqline(char *l)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevline != NULL) {
|
if (prevline) {
|
||||||
if ((prevlinecount == 1 && !dflag) ||
|
if ((prevlinecount == 1 && !dflag) ||
|
||||||
(prevlinecount != 1 && !uflag)) {
|
(prevlinecount != 1 && !uflag)) {
|
||||||
printf(countfmt, prevlinecount);
|
printf(countfmt, prevlinecount);
|
||||||
|
@ -46,7 +46,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
|
|||||||
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = 0;
|
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = 0;
|
||||||
size_t bufsiz = 0;
|
size_t bufsiz = 0;
|
||||||
|
|
||||||
if (sumfile == NULL)
|
if (!sumfile)
|
||||||
cfp = stdin;
|
cfp = stdin;
|
||||||
else if (!(cfp = fopen(sumfile, "r")))
|
else if (!(cfp = fopen(sumfile, "r")))
|
||||||
eprintf("fopen %s:", sumfile);
|
eprintf("fopen %s:", sumfile);
|
||||||
@ -81,7 +81,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
if (sumfile != NULL)
|
if (sumfile)
|
||||||
fclose(cfp);
|
fclose(cfp);
|
||||||
free(line);
|
free(line);
|
||||||
if (formatsucks > 0) {
|
if (formatsucks > 0) {
|
||||||
@ -111,7 +111,7 @@ cryptmain(int argc, char *argv[],
|
|||||||
mdprint(md, "<stdin>", sz);
|
mdprint(md, "<stdin>", sz);
|
||||||
} else {
|
} else {
|
||||||
for (; argc > 0; argc--) {
|
for (; argc > 0; argc--) {
|
||||||
if ((fp = fopen(*argv, "r")) == NULL) {
|
if (!(fp = fopen(*argv, "r"))) {
|
||||||
weprintf("fopen %s:", *argv);
|
weprintf("fopen %s:", *argv);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
|
@ -17,7 +17,7 @@ getlines(FILE *fp, struct linebuf *b)
|
|||||||
if (++b->nlines > b->capacity) {
|
if (++b->nlines > b->capacity) {
|
||||||
b->capacity += 512;
|
b->capacity += 512;
|
||||||
nline = realloc(b->lines, b->capacity * sizeof(*b->lines));
|
nline = realloc(b->lines, b->capacity * sizeof(*b->lines));
|
||||||
if (nline == NULL)
|
if (!nline)
|
||||||
eprintf("realloc:");
|
eprintf("realloc:");
|
||||||
b->lines = nline;
|
b->lines = nline;
|
||||||
}
|
}
|
||||||
|
12
uudecode.c
12
uudecode.c
@ -40,14 +40,14 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
parseheader(stdin, "<stdin>", "begin ", &mode, &fname);
|
parseheader(stdin, "<stdin>", "begin ", &mode, &fname);
|
||||||
if ((nfp = parsefile(fname)) == NULL)
|
if (!(nfp = parsefile(fname)))
|
||||||
eprintf("fopen %s:", fname);
|
eprintf("fopen %s:", fname);
|
||||||
uudecode(stdin, nfp);
|
uudecode(stdin, nfp);
|
||||||
} else {
|
} else {
|
||||||
if ((fp = fopen(argv[0], "r")) == NULL)
|
if (!(fp = fopen(argv[0], "r")))
|
||||||
eprintf("fopen %s:", argv[0]);
|
eprintf("fopen %s:", argv[0]);
|
||||||
parseheader(fp, argv[0], "begin ", &mode, &fname);
|
parseheader(fp, argv[0], "begin ", &mode, &fname);
|
||||||
if ((nfp = parsefile(fname)) == NULL)
|
if (!(nfp = parsefile(fname)))
|
||||||
eprintf("fopen %s:", fname);
|
eprintf("fopen %s:", fname);
|
||||||
uudecode(fp, nfp);
|
uudecode(fp, nfp);
|
||||||
}
|
}
|
||||||
@ -93,18 +93,18 @@ parseheader(FILE *fp, const char *s, const char *header, mode_t *mode, char **fn
|
|||||||
char *p, *q;
|
char *p, *q;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if (fgets(bufs, sizeof(bufs), fp) == NULL)
|
if (!fgets(bufs, sizeof(bufs), fp))
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
eprintf("%s: read error:", s);
|
eprintf("%s: read error:", s);
|
||||||
if (bufs[0] == '\0' || feof(fp))
|
if (bufs[0] == '\0' || feof(fp))
|
||||||
eprintf("empty or nil header string\n");
|
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");
|
eprintf("header string too long or non-newline terminated file\n");
|
||||||
p = bufs;
|
p = bufs;
|
||||||
if (strncmp(bufs, header, strlen(header)) != 0)
|
if (strncmp(bufs, header, strlen(header)) != 0)
|
||||||
eprintf("malformed header prefix\n");
|
eprintf("malformed header prefix\n");
|
||||||
p += strlen(header);
|
p += strlen(header);
|
||||||
if ((q = strchr(p, ' ')) == NULL)
|
if (!(q = strchr(p, ' ')))
|
||||||
eprintf("malformed mode string in header\n");
|
eprintf("malformed mode string in header\n");
|
||||||
*q++ = '\0';
|
*q++ = '\0';
|
||||||
/* now mode should be null terminated, q points to fname */
|
/* now mode should be null terminated, q points to fname */
|
||||||
|
Loading…
Reference in New Issue
Block a user