misc: simplify if clauses [oclint]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2016-07-04 22:09:10 +01:00
parent 10e8d7a324
commit 74ce680a3e
No known key found for this signature in database
GPG Key ID: A9553245FDE9B739
26 changed files with 104 additions and 158 deletions

View File

@ -632,22 +632,21 @@ static int execute(const char *progname, const char *progpath,
for (i=0; i <num_args; i++) for (i=0; i <num_args; i++)
argv[argc++] = xstrdup(args[i]); argv[argc++] = xstrdup(args[i]);
if (progress) { if (progress &&
if ((strcmp(type, "ext2") == 0) || ((strcmp(type, "ext2") == 0) ||
(strcmp(type, "ext3") == 0) || (strcmp(type, "ext3") == 0) ||
(strcmp(type, "ext4") == 0) || (strcmp(type, "ext4") == 0) ||
(strcmp(type, "ext4dev") == 0)) { (strcmp(type, "ext4dev") == 0))) {
char tmp[80];
tmp[0] = 0; char tmp[80];
if (!progress_active()) { tmp[0] = 0;
snprintf(tmp, 80, "-C%d", progress_fd); if (!progress_active()) {
inst->flags |= FLAG_PROGRESS; snprintf(tmp, 80, "-C%d", progress_fd);
} else if (progress_fd) inst->flags |= FLAG_PROGRESS;
snprintf(tmp, 80, "-C%d", progress_fd * -1); } else if (progress_fd)
if (tmp[0]) snprintf(tmp, 80, "-C%d", progress_fd * -1);
argv[argc++] = xstrdup(tmp); if (tmp[0])
} argv[argc++] = xstrdup(tmp);
} }
argv[argc++] = xstrdup(fs_get_device(fs)); argv[argc++] = xstrdup(fs_get_device(fs));

View File

@ -403,10 +403,8 @@ static void do_uncompress(char *path, int outfd, unsigned long offset,
size); size);
} }
size -= out; size -= out;
if (*extract_dir != '\0') if (*extract_dir != '\0' && write(outfd, outbuffer, out) < 0)
if (write(outfd, outbuffer, out) < 0) err(FSCK_EX_ERROR, _("write failed: %s"), path);
err(FSCK_EX_ERROR, _("write failed: %s"),
path);
curr = next; curr = next;
} while (size); } while (size);
} }
@ -629,9 +627,8 @@ static void test_fs(int start)
_("directory data end (%lu) != file data start (%lu)"), _("directory data end (%lu) != file data start (%lu)"),
end_dir, start_data); end_dir, start_data);
} }
if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) if (super.flags & CRAMFS_FLAG_FSID_VERSION_2 && end_data > super.size)
if (end_data > super.size) errx(FSCK_EX_UNCORRECTED, _("invalid file data offset"));
errx(FSCK_EX_UNCORRECTED, _("invalid file data offset"));
iput(root); /* free(root) */ iput(root); /* free(root) */
} }

View File

@ -1333,10 +1333,9 @@ main(int argc, char **argv) {
usage(stderr); usage(stderr);
check_mount(); /* trying to check a mounted filesystem? */ check_mount(); /* trying to check a mounted filesystem? */
if (repair && !automatic) { if (repair && !automatic && (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)))
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) die(_("need terminal for interactive repairs"));
die(_("need terminal for interactive repairs"));
}
device_fd = open(device_name, repair ? O_RDWR : O_RDONLY); device_fd = open(device_name, repair ? O_RDWR : O_RDONLY);
if (device_fd < 0) if (device_fd < 0)
die(_("cannot open %s: %s"), device_name, strerror(errno)); die(_("cannot open %s: %s"), device_name, strerror(errno));

View File

@ -313,10 +313,9 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
if (dirent->d_name[0] == '.') { if (dirent->d_name[0] == '.') {
if (dirent->d_name[1] == '\0') if (dirent->d_name[1] == '\0')
continue; continue;
if (dirent->d_name[1] == '.') { if (dirent->d_name[1] == '.' &&
if (dirent->d_name[2] == '\0') dirent->d_name[2] == '\0')
continue; continue;
}
} }
namelen = strlen(dirent->d_name); namelen = strlen(dirent->d_name);
if (namelen > MAX_INPUT_NAMELEN) { if (namelen > MAX_INPUT_NAMELEN) {
@ -352,11 +351,9 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub); entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);
} else if (S_ISREG(st.st_mode)) { } else if (S_ISREG(st.st_mode)) {
entry->path = xstrdup(path); entry->path = xstrdup(path);
if (entry->size) { if (entry->size && entry->size >= (1 << CRAMFS_SIZE_WIDTH)) {
if (entry->size >= (1 << CRAMFS_SIZE_WIDTH)) { warn_size = 1;
warn_size = 1; entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
}
} }
} else if (S_ISLNK(st.st_mode)) { } else if (S_ISLNK(st.st_mode)) {
entry->path = xstrdup(path); entry->path = xstrdup(path);

View File

@ -669,15 +669,11 @@ static int find_super_magic(const struct fs_control *ctl)
case 1: case 1:
if (ctl->fs_namelen == 14) if (ctl->fs_namelen == 14)
return MINIX_SUPER_MAGIC; return MINIX_SUPER_MAGIC;
else return MINIX_SUPER_MAGIC2;
return MINIX_SUPER_MAGIC2;
break;
case 2: case 2:
if (ctl->fs_namelen == 14) if (ctl->fs_namelen == 14)
return MINIX2_SUPER_MAGIC; return MINIX2_SUPER_MAGIC;
else return MINIX2_SUPER_MAGIC2;
return MINIX2_SUPER_MAGIC2;
break;
case 3: case 3:
return MINIX3_SUPER_MAGIC; return MINIX3_SUPER_MAGIC;
default: default:

View File

@ -785,10 +785,8 @@ int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
/* /*
* unpartitioned device * unpartitioned device
*/ */
if (diskname && len) { if (diskname && len && !sysfs_get_devname(&cxt, diskname, len))
if (!sysfs_get_devname(&cxt, diskname, len)) goto err;
goto err;
}
if (diskdevno) if (diskdevno)
*diskdevno = dev; *diskdevno = dev;

View File

@ -385,10 +385,8 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
p += len; p += len;
} }
if (flags & ISO_8601_TIMEZONE) { if (flags & ISO_8601_TIMEZONE && strftime(p, bufsz, "%z", tm) <= 0)
if (strftime(p, bufsz, "%z", tm) <= 0) return -1;
return -1;
}
return 0; return 0;
} }

View File

@ -1204,20 +1204,18 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
(uintmax_t)start, (uintmax_t)stop, cxt->grain)); (uintmax_t)start, (uintmax_t)stop, cxt->grain));
} }
if (stop < limit) { if (stop < limit && isrel && alignment_required(cxt)) {
if (isrel && alignment_required(cxt)) { /* the last sector has not been exactly requested (but
/* the last sector has not been exactly requested (but * defined by +size{K,M,G} convention), so be smart and
* defined by +size{K,M,G} convention), so be smart and * align the end of the partition. The next partition
* align the end of the partition. The next partition * will start at phy.block boundary.
* will start at phy.block boundary. */
*/ stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
stop = fdisk_align_lba_in_range(cxt, stop, start, limit); if (stop > start)
if (stop > start) stop -= 1;
stop -= 1; if (stop > limit)
if (stop > limit) stop = limit;
stop = limit; DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
}
} }
set_partition(cxt, n, 0, start, stop, sys, fdisk_partition_is_bootable(pa)); set_partition(cxt, n, 0, start, stop, sys, fdisk_partition_is_bootable(pa));

View File

@ -592,9 +592,8 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
if (sgi_get_num_sectors(cxt, i) != 0) { if (sgi_get_num_sectors(cxt, i) != 0) {
Index[sortcount++] = i; Index[sortcount++] = i;
if (sgi_get_sysid(cxt, i) == SGI_TYPE_ENTIRE_DISK if (sgi_get_sysid(cxt, i) == SGI_TYPE_ENTIRE_DISK
&& entire++ == 1) { && entire++ == 1 && verbose) {
if (verbose) fdisk_info(cxt, _("More than one entire "
fdisk_info(cxt, _("More than one entire "
"disk entry present.")); "disk entry present."));
} }
} }

View File

@ -749,11 +749,10 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs)
res = merge_optstr(fs->vfs_optstr, fs->fs_optstr); res = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
if (!res && errno) if (!res && errno)
return NULL; return NULL;
if (fs->user_optstr) { if (fs->user_optstr &&
if (mnt_optstr_append_option(&res, fs->user_optstr, NULL)) { mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
free(res); free(res);
res = NULL; res = NULL;
}
} }
return res; return res;
} }

View File

@ -454,10 +454,8 @@ static int check_option(const char *haystack, size_t len,
size_t plen = sep ? (size_t) (sep - p) : size_t plen = sep ? (size_t) (sep - p) :
len - (p - haystack); len - (p - haystack);
if (plen == needle_len) { if (plen == needle_len && !strncmp(p, needle, plen))
if (!strncmp(p, needle, plen)) return !no; /* foo or nofoo was found */
return !no; /* foo or nofoo was found */
}
p += plen; p += plen;
} }

View File

@ -1105,10 +1105,8 @@ int main(int argc, char **argv)
} }
signum = sigtimedwait(&set, NULL, &sigwait); signum = sigtimedwait(&set, NULL, &sigwait);
if (signum != SIGCHLD) { if (signum != SIGCHLD && signum < 0 && errno == EAGAIN)
if (signum < 0 && errno == EAGAIN) break;
break;
}
} while (1); } while (1);

View File

@ -394,9 +394,8 @@ int main(int argc, char **argv)
in = dump(in, filename, follow, out); in = dump(in, filename, follow, out);
} }
if (out != stdout) if (out != stdout && close_stream(out))
if (close_stream(out)) err(EXIT_FAILURE, _("write failed"));
err(EXIT_FAILURE, _("write failed"));
if (in && in != stdin) if (in && in != stdin)
fclose(in); fclose(in);

View File

@ -354,10 +354,9 @@ int main(int argc, char *argv[])
* which means they can be translated. */ * which means they can be translated. */
printf(_("Would you like to edit %s now [y/n]? "), orig_file); printf(_("Would you like to edit %s now [y/n]? "), orig_file);
if (fgets(response, sizeof(response), stdin)) { if (fgets(response, sizeof(response), stdin) &&
if (rpmatch(response) == RPMATCH_YES) rpmatch(response) == RPMATCH_YES)
edit_file(1); edit_file(1);
}
} }
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -892,10 +892,8 @@ static int week_number(int day, int month, int32_t year, const struct cal_contro
month = JANUARY; month = JANUARY;
yday = day_in_year(day,month,year); yday = day_in_year(day,month,year);
if (year == REFORMATION_YEAR) { if (year == REFORMATION_YEAR && yday >= YDAY_AFTER_MISSING)
if (yday >= YDAY_AFTER_MISSING) fday -= NUMBER_MISSING_DAYS;
fday -= NUMBER_MISSING_DAYS;
}
/* Last year is last year */ /* Last year is last year */
if (yday + fday < DAYS_IN_WEEK) if (yday + fday < DAYS_IN_WEEK)

View File

@ -121,10 +121,8 @@ static void randomness_from_files(struct mcookie_control *ctl)
"Got %zu bytes from %s\n", count), "Got %zu bytes from %s\n", count),
count, fname); count, fname);
if (fd != STDIN_FILENO) if (fd != STDIN_FILENO && close(fd))
if (close(fd)) err(EXIT_FAILURE, _("closing %s failed"), fname);
err(EXIT_FAILURE,
_("closing %s failed"), fname);
} }
} }
} }

View File

@ -371,9 +371,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
if (ftruncate(fd_pidfile, 0)) if (ftruncate(fd_pidfile, 0))
err(EXIT_FAILURE, _("could not truncate file: %s"), pidfile_path); err(EXIT_FAILURE, _("could not truncate file: %s"), pidfile_path);
write_all(fd_pidfile, reply_buf, strlen(reply_buf)); write_all(fd_pidfile, reply_buf, strlen(reply_buf));
if (fd_pidfile > 1) if (fd_pidfile > 1 && close_fd(fd_pidfile) != 0)
if (close_fd(fd_pidfile) != 0) /* Unlock the pid file */ err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
} }
} }

View File

@ -1116,8 +1116,6 @@ static int parse_kmsg_record(struct dmesg_control *ctl,
/* D) optional fields (ignore) */ /* D) optional fields (ignore) */
p = skip_item(p, end, ";"); p = skip_item(p, end, ";");
if (LAST_KMSG_FIELD(p))
goto mesg;
mesg: mesg:
/* E) message text */ /* E) message text */
@ -1391,12 +1389,11 @@ int main(int argc, char *argv[])
if (argc > 1) if (argc > 1)
usage(stderr); usage(stderr);
if (is_timefmt(&ctl, RELTIME) || if ((is_timefmt(&ctl, RELTIME) ||
is_timefmt(&ctl, CTIME) || is_timefmt(&ctl, CTIME) ||
is_timefmt(&ctl, ISO8601)) { is_timefmt(&ctl, ISO8601))
if (dmesg_get_boot_time(&ctl.boot_time) != 0) && dmesg_get_boot_time(&ctl.boot_time) != 0)
ctl.time_fmt = DMESG_TIMEFTM_NONE; ctl.time_fmt = DMESG_TIMEFTM_NONE;
}
if (delta) if (delta)
switch (ctl.time_fmt) { switch (ctl.time_fmt) {

View File

@ -407,9 +407,8 @@ int main(int argc, char **argv)
} }
} }
if (rm_all) if (rm_all && remove_all(what_all))
if (remove_all(what_all)) ret++;
ret++;
/* print usage if we still have some arguments left over */ /* print usage if we still have some arguments left over */
if (optind < argc) { if (optind < argc) {

View File

@ -501,12 +501,9 @@ int main(int argc, char **argv)
} }
} }
if (ctl.clock_mode == CM_AUTO) { if (ctl.clock_mode == CM_AUTO && read_clock_mode(&ctl) < 0) {
if (read_clock_mode(&ctl) < 0) { printf(_("%s: assuming RTC uses UTC ...\n"), program_invocation_short_name);
printf(_("%s: assuming RTC uses UTC ...\n"), ctl.clock_mode = CM_UTC;
program_invocation_short_name);
ctl.clock_mode = CM_UTC;
}
} }
if (ctl.verbose) if (ctl.verbose)

View File

@ -781,9 +781,8 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, errx(EXIT_FAILURE,
_("--[re]gid requires --keep-groups, --clear-groups, or --groups")); _("--[re]gid requires --keep-groups, --clear-groups, or --groups"));
if (opts.nnp) if (opts.nnp && prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) err(EXIT_FAILURE, _("disallow granting new privileges failed"));
err(EXIT_FAILURE, _("disallow granting new privileges failed"));
if (opts.selinux_label) if (opts.selinux_label)
do_selinux_label(opts.selinux_label); do_selinux_label(opts.selinux_label);
@ -820,9 +819,8 @@ int main(int argc, char **argv)
err(SETPRIV_EXIT_PRIVERR, _("setgroups failed")); err(SETPRIV_EXIT_PRIVERR, _("setgroups failed"));
} }
if (opts.have_securebits) if (opts.have_securebits && prctl(PR_SET_SECUREBITS, opts.securebits, 0, 0, 0) != 0)
if (prctl(PR_SET_SECUREBITS, opts.securebits, 0, 0, 0) != 0) err(SETPRIV_EXIT_PRIVERR, _("set process securebits failed"));
err(SETPRIV_EXIT_PRIVERR, _("set process securebits failed"));
if (opts.bounding_set) { if (opts.bounding_set) {
do_caps(CAPNG_BOUNDING_SET, opts.bounding_set); do_caps(CAPNG_BOUNDING_SET, opts.bounding_set);

View File

@ -109,10 +109,8 @@ int main(int argc, char **argv)
/* cannot happen */ /* cannot happen */
err(EXIT_FAILURE, _("setsid failed")); err(EXIT_FAILURE, _("setsid failed"));
if (ctty) { if (ctty && ioctl(STDIN_FILENO, TIOCSCTTY, 1))
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1)) err(EXIT_FAILURE, _("failed to set the controlling terminal"));
err(EXIT_FAILURE, _("failed to set the controlling terminal"));
}
execvp(argv[optind], argv + optind); execvp(argv[optind], argv + optind);
err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]); err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
} }

View File

@ -502,21 +502,16 @@ int main(int argc, char **argv)
login_argv[login_argc] = NULL; /* last login argv */ login_argv[login_argc] = NULL; /* last login argv */
if (options.chroot) { if (options.chroot && chroot(options.chroot) < 0)
if (chroot(options.chroot) < 0) log_err(_("%s: can't change root directory %s: %m"),
log_err(_("%s: can't change root directory %s: %m"), options.tty, options.chroot);
options.tty, options.chroot); if (options.chdir && chdir(options.chdir) < 0)
} log_err(_("%s: can't change working directory %s: %m"),
if (options.chdir) { options.tty, options.chdir);
if (chdir(options.chdir) < 0) if (options.nice && nice(options.nice) < 0)
log_err(_("%s: can't change working directory %s: %m"), log_warn(_("%s: can't change process priority: %m"),
options.tty, options.chdir); options.tty);
}
if (options.nice) {
if (nice(options.nice) < 0)
log_warn(_("%s: can't change process priority: %m"),
options.tty);
}
free(options.osrelease); free(options.osrelease);
#ifdef DEBUGGING #ifdef DEBUGGING
if (close_stream(dbf) != 0) if (close_stream(dbf) != 0)

View File

@ -809,11 +809,9 @@ static void screendump(struct setterm_control *ctl)
/* Some options are applicable when terminal is virtual console. */ /* Some options are applicable when terminal is virtual console. */
static int vc_only(struct setterm_control *ctl, const char *err) static int vc_only(struct setterm_control *ctl, const char *err)
{ {
if (!ctl->vcterm) { if (!ctl->vcterm && err)
if (err) warnx(_("terminal %s does not support %s"),
warnx(_("terminal %s does not support %s"), ctl->opt_te_terminal_name, err);
ctl->opt_te_terminal_name, err);
}
return ctl->vcterm; return ctl->vcterm;
} }

View File

@ -460,15 +460,12 @@ isint: cs[3] = '\0';
fs->bcnt < hex->blocksize && fs->bcnt < hex->blocksize &&
!(fu->flags&F_SETREP) && fu->bcnt) !(fu->flags&F_SETREP) && fu->bcnt)
fu->reps += (hex->blocksize - fs->bcnt) / fu->bcnt; fu->reps += (hex->blocksize - fs->bcnt) / fu->bcnt;
if (fu->reps > 1) { if (fu->reps > 1 && !list_empty(&fu->prlist)) {
if (!list_empty(&fu->prlist)) { pr = list_last_entry(&fu->prlist, struct hexdump_pr, prlist);
pr = list_last_entry(&fu->prlist, for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
struct hexdump_pr, prlist); p2 = isspace(*p1) ? p1 : NULL;
for (p1 = pr->fmt, p2 = NULL; *p1; ++p1) if (p2)
p2 = isspace(*p1) ? p1 : NULL; pr->nospace = p2;
if (p2)
pr->nospace = p2;
}
} }
} }
} }

View File

@ -74,11 +74,9 @@ static void tailf(const char *filename, size_t lines, struct stat *st)
if (data[i] == '\n') if (data[i] == '\n')
lines++; lines++;
while (i) { while (i) {
if (data[i] == '\n') { if (data[i] == '\n' && --lines == 0) {
if (--lines == 0) { i++;
i++; break;
break;
}
} }
i--; i--;
} }