Shorter NULL checks

This commit is contained in:
Arun Prakash Jana 2019-04-11 19:27:38 +05:30
parent 69328f5b03
commit 6175f33b75
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -741,7 +741,7 @@ static char *xdirname(const char *path)
/* Find last '/'. */ /* Find last '/'. */
last_slash = xmemrchr((uchar *)buf, '/', strlen(buf)); last_slash = xmemrchr((uchar *)buf, '/', strlen(buf));
if (last_slash != NULL && last_slash != buf && last_slash[1] == '\0') { if (last_slash && last_slash != buf && last_slash[1] == '\0') {
/* Determine whether all remaining characters are slashes. */ /* Determine whether all remaining characters are slashes. */
for (runp = last_slash; runp != buf; --runp) for (runp = last_slash; runp != buf; --runp)
if (runp[-1] != '/') if (runp[-1] != '/')
@ -752,7 +752,7 @@ static char *xdirname(const char *path)
last_slash = xmemrchr((uchar *)buf, '/', runp - buf); last_slash = xmemrchr((uchar *)buf, '/', runp - buf);
} }
if (last_slash != NULL) { if (last_slash) {
/* Determine whether all remaining characters are slashes. */ /* Determine whether all remaining characters are slashes. */
for (runp = last_slash; runp != buf; --runp) for (runp = last_slash; runp != buf; --runp)
if (runp[-1] != '/') if (runp[-1] != '/')
@ -932,7 +932,7 @@ static bool initcurses(void)
} else if (!initscr()) { } else if (!initscr()) {
char *term = getenv("TERM"); char *term = getenv("TERM");
if (term != NULL) if (term)
fprintf(stderr, "error opening TERM: %s\n", term); fprintf(stderr, "error opening TERM: %s\n", term);
else else
fprintf(stderr, "initscr!\n"); fprintf(stderr, "initscr!\n");
@ -1110,7 +1110,7 @@ static bool xdiraccess(const char *path)
{ {
DIR *dirp = opendir(path); DIR *dirp = opendir(path);
if (dirp == NULL) { if (!dirp) {
printwarn(); printwarn();
return FALSE; return FALSE;
} }
@ -2343,8 +2343,8 @@ static bool show_stats(const char *fpath, const char *fname, const struct stat *
DPRINTF_S(g_buf); DPRINTF_S(g_buf);
fp = popen(g_buf, "r"); fp = popen(g_buf, "r");
if (fp != NULL) { if (fp) {
while (fgets(g_buf, CMD_LEN_MAX - 1, fp) != NULL) while (fgets(g_buf, CMD_LEN_MAX - 1, fp))
dprintf(fd, "%s", g_buf); dprintf(fd, "%s", g_buf);
pclose(fp); pclose(fp);
} }
@ -2556,7 +2556,7 @@ static int dentfill(char *path, struct entry **dents)
DIR *dirp = opendir(path); DIR *dirp = opendir(path);
static uint open_max; static uint open_max;
if (dirp == NULL) if (!dirp)
return 0; return 0;
int fd = dirfd(dirp); int fd = dirfd(dirp);
@ -2576,7 +2576,7 @@ static int dentfill(char *path, struct entry **dents)
open_max = max_openfds(); open_max = max_openfds();
} }
while ((dp = readdir(dirp)) != NULL) { while ((dp = readdir(dirp))) {
namep = dp->d_name; namep = dp->d_name;
/* Skip self and parent */ /* Skip self and parent */
@ -2628,7 +2628,7 @@ static int dentfill(char *path, struct entry **dents)
if (n == total_dents) { if (n == total_dents) {
total_dents += ENTRY_INCR; total_dents += ENTRY_INCR;
*dents = xrealloc(*dents, total_dents * sizeof(**dents)); *dents = xrealloc(*dents, total_dents * sizeof(**dents));
if (*dents == NULL) { if (!*dents) {
free(pnamebuf); free(pnamebuf);
closedir(dirp); closedir(dirp);
errexit(); errexit();
@ -2642,7 +2642,7 @@ static int dentfill(char *path, struct entry **dents)
pnb = pnamebuf; pnb = pnamebuf;
pnamebuf = (char *)xrealloc(pnamebuf, namebuflen); pnamebuf = (char *)xrealloc(pnamebuf, namebuflen);
if (pnamebuf == NULL) { if (!pnamebuf) {
free(*dents); free(*dents);
closedir(dirp); closedir(dirp);
errexit(); errexit();
@ -3247,7 +3247,7 @@ nochange:
goto begin; goto begin;
} }
if (get_bm_loc(newpath, fd) == NULL) { if (!get_bm_loc(newpath, fd)) {
printwait(messages[STR_INVBM_KEY], &presel); printwait(messages[STR_INVBM_KEY], &presel);
goto nochange; goto nochange;
} }
@ -3676,7 +3676,7 @@ nochange:
break; break;
} }
if (tmp == NULL || tmp[0] == '\0') if (!tmp || !*tmp)
break; break;
/* Allow only relative, same dir paths */ /* Allow only relative, same dir paths */
@ -4120,7 +4120,7 @@ int main(int argc, char *argv[])
} }
if (ipath) { /* Open a bookmark directly */ if (ipath) { /* Open a bookmark directly */
if (ipath[1] || get_bm_loc(cwd, *ipath) == NULL) { if (ipath[1] || !get_bm_loc(cwd, *ipath)) {
fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]); fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]);
return 1; return 1;
} }
@ -4129,7 +4129,7 @@ int main(int argc, char *argv[])
} else if (argc == optind) { } else if (argc == optind) {
/* Start in the current directory */ /* Start in the current directory */
ipath = getcwd(cwd, PATH_MAX); ipath = getcwd(cwd, PATH_MAX);
if (ipath == NULL) if (!ipath)
ipath = "/"; ipath = "/";
} else { } else {
ipath = realpath(argv[optind], cwd); ipath = realpath(argv[optind], cwd);
@ -4198,7 +4198,7 @@ int main(int argc, char *argv[])
g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", HOME_LEN_MAX); g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", HOME_LEN_MAX);
else { else {
copier = getenv("TMPDIR"); copier = getenv("TMPDIR");
if (copier != NULL) if (copier)
g_tmpfplen = xstrlcpy(g_tmpfpath, copier, HOME_LEN_MAX); g_tmpfplen = xstrlcpy(g_tmpfpath, copier, HOME_LEN_MAX);
} }