All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/13] pull: OCLint static code analysis changes
@ 2016-07-17 13:00 Sami Kerola
  2016-07-17 13:00 ` [PATCH 01/13] misc: simplify if clauses [oclint] Sami Kerola
                   ` (13 more replies)
  0 siblings, 14 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Hello,

Just while back I heard first time a tool called OCLint[1] and I decided to
give it a try.  The OCLint seems to print a lot of warnings that do not
appear to that important to address.  It seems the tools is in it best to
find where code is unnecessarily complicated - and the changes are mostly
about improving such segments.  IMHO only the shadowing and libblkid
debugging fixes in this pull request are a little bit more important.

[1] http://oclint.org/

----------------------------------------------------------------
The following changes since commit b8fd5c055889edcefdd97afa2abb35b71e6fa369:
  tests: fix ttyutils test (2016-07-15 10:11:35 +0200)
are available in the git repository at:
  git://github.com/kerolasa/lelux-utiliteetit.git oclint
for you to fetch changes up to 5c5e25f2a96c458cd641fbf119c81813d27f1da3:
  libblkid: fix debugging macro [oclint] (2016-07-17 13:49:51 +0100)
----------------------------------------------------------------

Sami Kerola (13):
  misc: simplify if clauses [oclint]
  switch_root: simplify code and reduce indentation [oclint]
  libfdisk: collapse indentation [oclint]
  lslogins: simplify if clause and move definition and comments [oclint]
  libblkid: simplify if clause [oclint]
  logger: simplify if clause [oclint]
  syspriv: flip inverted logic [oclint]
  libmount, look: remove dead code [oclint]
  dmesg: drop core at impossible case in read_buffer() [oclint]
  misc: fix declarations shadowing variables in the global scope [oclint]
  setterm: fix declarations shadowing variables in the global scope [oclint]
  agetty: move unreachable code to pre-processor #else segment [oclint]
  libblkid: fix debugging macro [oclint]

 disk-utils/fsck.c              | 31 +++++++--------
 disk-utils/fsck.cramfs.c       | 11 ++----
 disk-utils/fsck.minix.c        |  7 ++--
 disk-utils/mkfs.cramfs.c       | 15 +++----
 disk-utils/mkfs.minix.c        |  8 +---
 lib/sysfs.c                    |  6 +--
 lib/timeutils.c                |  6 +--
 libblkid/src/probe.c           | 10 ++---
 libblkid/src/superblocks/zfs.c | 32 +++++++--------
 libfdisk/src/dos.c             | 26 ++++++-------
 libfdisk/src/sgi.c             |  5 +--
 libfdisk/src/sun.c             | 48 +++++++++++------------
 libmount/src/context_mount.c   |  1 -
 libmount/src/context_umount.c  |  1 -
 libmount/src/fs.c              |  9 ++---
 libmount/src/utils.c           |  6 +--
 login-utils/last.c             |  6 +--
 login-utils/lslogins.c         | 26 ++++++-------
 login-utils/sulogin.c          |  6 +--
 login-utils/utmpdump.c         |  5 +--
 login-utils/vipw.c             |  7 ++--
 misc-utils/cal.c               |  6 +--
 misc-utils/logger.c            | 62 ++++++++++++++---------------
 misc-utils/look.c              |  2 -
 misc-utils/mcookie.c           |  6 +--
 misc-utils/uuidd.c             |  5 +--
 sys-utils/dmesg.c              | 29 +++++++-------
 sys-utils/ipcrm.c              | 13 +++----
 sys-utils/lsipc.c              |  6 +--
 sys-utils/rtcwake.c            | 15 +++----
 sys-utils/setpriv.c            | 22 +++++------
 sys-utils/setsid.c             |  6 +--
 sys-utils/switch_root.c        | 29 +++++++-------
 term-utils/agetty.c            | 30 +++++++-------
 term-utils/setterm.c           | 88 +++++++++++++++++++++---------------------
 text-utils/hexdump-parse.c     | 15 +++----
 text-utils/tailf.c             |  8 ++--
 37 files changed, 274 insertions(+), 340 deletions(-)

-- 
2.9.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/13] misc: simplify if clauses [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 02/13] switch_root: simplify code and reduce indentation [oclint] Sami Kerola
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 disk-utils/fsck.c          | 31 +++++++++++++++----------------
 disk-utils/fsck.cramfs.c   | 11 ++++-------
 disk-utils/fsck.minix.c    |  7 +++----
 disk-utils/mkfs.cramfs.c   | 15 ++++++---------
 disk-utils/mkfs.minix.c    |  8 ++------
 lib/sysfs.c                |  6 ++----
 lib/timeutils.c            |  6 ++----
 libfdisk/src/dos.c         | 26 ++++++++++++--------------
 libfdisk/src/sgi.c         |  5 ++---
 libmount/src/fs.c          |  9 ++++-----
 libmount/src/utils.c       |  6 ++----
 login-utils/sulogin.c      |  6 ++----
 login-utils/utmpdump.c     |  5 ++---
 login-utils/vipw.c         |  7 +++----
 misc-utils/cal.c           |  6 ++----
 misc-utils/mcookie.c       |  6 ++----
 misc-utils/uuidd.c         |  5 ++---
 sys-utils/dmesg.c          | 13 +++++--------
 sys-utils/ipcrm.c          |  5 ++---
 sys-utils/rtcwake.c        |  9 +++------
 sys-utils/setpriv.c        | 10 ++++------
 sys-utils/setsid.c         |  6 ++----
 term-utils/agetty.c        | 25 ++++++++++---------------
 term-utils/setterm.c       |  8 +++-----
 text-utils/hexdump-parse.c | 15 ++++++---------
 text-utils/tailf.c         |  8 +++-----
 26 files changed, 105 insertions(+), 159 deletions(-)

diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
index eede038..dd89527 100644
--- a/disk-utils/fsck.c
+++ b/disk-utils/fsck.c
@@ -632,22 +632,21 @@ static int execute(const char *progname, const char *progpath,
 	for (i=0; i <num_args; i++)
 		argv[argc++] = xstrdup(args[i]);
 
-	if (progress) {
-		if ((strcmp(type, "ext2") == 0) ||
-		    (strcmp(type, "ext3") == 0) ||
-		    (strcmp(type, "ext4") == 0) ||
-		    (strcmp(type, "ext4dev") == 0)) {
-			char tmp[80];
-
-			tmp[0] = 0;
-			if (!progress_active()) {
-				snprintf(tmp, 80, "-C%d", progress_fd);
-				inst->flags |= FLAG_PROGRESS;
-			} else if (progress_fd)
-				snprintf(tmp, 80, "-C%d", progress_fd * -1);
-			if (tmp[0])
-				argv[argc++] = xstrdup(tmp);
-		}
+	if (progress &&
+	       ((strcmp(type, "ext2") == 0) ||
+		(strcmp(type, "ext3") == 0) ||
+		(strcmp(type, "ext4") == 0) ||
+		(strcmp(type, "ext4dev") == 0))) {
+
+		char tmp[80];
+		tmp[0] = 0;
+		if (!progress_active()) {
+			snprintf(tmp, 80, "-C%d", progress_fd);
+			inst->flags |= FLAG_PROGRESS;
+		} else if (progress_fd)
+			snprintf(tmp, 80, "-C%d", progress_fd * -1);
+		if (tmp[0])
+			argv[argc++] = xstrdup(tmp);
 	}
 
 	argv[argc++] = xstrdup(fs_get_device(fs));
diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index ef311c1..d904037 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -403,10 +403,8 @@ static void do_uncompress(char *path, int outfd, unsigned long offset,
 				     size);
 		}
 		size -= out;
-		if (*extract_dir != '\0')
-			if (write(outfd, outbuffer, out) < 0)
-				err(FSCK_EX_ERROR, _("write failed: %s"),
-				    path);
+		if (*extract_dir != '\0' && write(outfd, outbuffer, out) < 0)
+			err(FSCK_EX_ERROR, _("write failed: %s"), path);
 		curr = next;
 	} while (size);
 }
@@ -629,9 +627,8 @@ static void test_fs(int start)
 			     _("directory data end (%lu) != file data start (%lu)"),
 			     end_dir, start_data);
 	}
-	if (super.flags & CRAMFS_FLAG_FSID_VERSION_2)
-		if (end_data > super.size)
-			errx(FSCK_EX_UNCORRECTED, _("invalid file data offset"));
+	if (super.flags & CRAMFS_FLAG_FSID_VERSION_2 && end_data > super.size)
+		errx(FSCK_EX_UNCORRECTED, _("invalid file data offset"));
 
 	iput(root);		/* free(root) */
 }
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index 726f5da..97e558b 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -1333,10 +1333,9 @@ main(int argc, char **argv) {
 		usage(stderr);
 
 	check_mount();		/* trying to check a mounted filesystem? */
-	if (repair && !automatic) {
-		if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
-			die(_("need terminal for interactive repairs"));
-	}
+	if (repair && !automatic && (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)))
+		die(_("need terminal for interactive repairs"));
+
 	device_fd = open(device_name, repair ? O_RDWR : O_RDONLY);
 	if (device_fd < 0)
 		die(_("cannot open %s: %s"), device_name, strerror(errno));
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 65ad356..bb1e4d0 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -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[1] == '\0')
 				continue;
-			if (dirent->d_name[1] == '.') {
-				if (dirent->d_name[2] == '\0')
-					continue;
-			}
+			if (dirent->d_name[1] == '.' &&
+			    dirent->d_name[2] == '\0')
+				continue;
 		}
 		namelen = strlen(dirent->d_name);
 		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);
 		} else if (S_ISREG(st.st_mode)) {
 			entry->path = xstrdup(path);
-			if (entry->size) {
-				if (entry->size >= (1 << CRAMFS_SIZE_WIDTH)) {
-					warn_size = 1;
-					entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
-				}
+			if (entry->size && entry->size >= (1 << CRAMFS_SIZE_WIDTH)) {
+				warn_size = 1;
+				entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
 			}
 		} else if (S_ISLNK(st.st_mode)) {
 			entry->path = xstrdup(path);
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index d4a576f..0e26966 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -669,15 +669,11 @@ static int find_super_magic(const struct fs_control *ctl)
 	case 1:
 		if (ctl->fs_namelen == 14)
 			return MINIX_SUPER_MAGIC;
-		else
-			return MINIX_SUPER_MAGIC2;
-		break;
+		return MINIX_SUPER_MAGIC2;
 	case 2:
 		if (ctl->fs_namelen == 14)
 			return MINIX2_SUPER_MAGIC;
-		else
-			return MINIX2_SUPER_MAGIC2;
-		break;
+		return MINIX2_SUPER_MAGIC2;
 	case 3:
 		return MINIX3_SUPER_MAGIC;
 	default:
diff --git a/lib/sysfs.c b/lib/sysfs.c
index f52b7a8..b52446c 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -785,10 +785,8 @@ int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
         /*
          * unpartitioned device
          */
-        if (diskname && len) {
-            if (!sysfs_get_devname(&cxt, diskname, len))
-                goto err;
-        }
+        if (diskname && len && !sysfs_get_devname(&cxt, diskname, len))
+            goto err;
         if (diskdevno)
             *diskdevno = dev;
 
diff --git a/lib/timeutils.c b/lib/timeutils.c
index fd9aa3e..608e6bd 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -385,10 +385,8 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 		p += len;
 	}
 
-	if (flags & ISO_8601_TIMEZONE) {
-		if (strftime(p, bufsz, "%z", tm) <= 0)
-			return -1;
-	}
+	if (flags & ISO_8601_TIMEZONE && strftime(p, bufsz, "%z", tm) <= 0)
+		return -1;
 
 	return 0;
 }
diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c
index b2e1c60..5ea56c2 100644
--- a/libfdisk/src/dos.c
+++ b/libfdisk/src/dos.c
@@ -1204,20 +1204,18 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
 			    (uintmax_t)start,  (uintmax_t)stop, cxt->grain));
 	}
 
-	if (stop < limit) {
-		if (isrel && alignment_required(cxt)) {
-			/* the last sector has not been exactly requested (but
-			 * defined by +size{K,M,G} convention), so be smart and
-			 * align the end of the partition. The next partition
-			 * will start at phy.block boundary.
-			 */
-			stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
-			if (stop > start)
-				stop -= 1;
-			if (stop > limit)
-				stop = limit;
-			DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
-		}
+	if (stop < limit && isrel && alignment_required(cxt)) {
+		/* the last sector has not been exactly requested (but
+		 * defined by +size{K,M,G} convention), so be smart and
+		 * align the end of the partition. The next partition
+		 * will start at phy.block boundary.
+		 */
+		stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
+		if (stop > start)
+			stop -= 1;
+		if (stop > limit)
+			stop = limit;
+		DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
 	}
 
 	set_partition(cxt, n, 0, start, stop, sys, fdisk_partition_is_bootable(pa));
diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c
index 73f9049..0ccf245 100644
--- a/libfdisk/src/sgi.c
+++ b/libfdisk/src/sgi.c
@@ -592,9 +592,8 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
 		if (sgi_get_num_sectors(cxt, i) != 0) {
 			Index[sortcount++] = i;
 			if (sgi_get_sysid(cxt, i) == SGI_TYPE_ENTIRE_DISK
-			    && entire++ == 1) {
-				if (verbose)
-					fdisk_info(cxt, _("More than one entire "
+			    && entire++ == 1 && verbose) {
+				fdisk_info(cxt, _("More than one entire "
 						"disk entry present."));
 			}
 		}
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
index 9cb3293..c92b6ab 100644
--- a/libmount/src/fs.c
+++ b/libmount/src/fs.c
@@ -749,11 +749,10 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs)
 	res = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
 	if (!res && errno)
 		return NULL;
-	if (fs->user_optstr) {
-		if (mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
-			free(res);
-			res = NULL;
-		}
+	if (fs->user_optstr &&
+	    mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
+		free(res);
+		res = NULL;
 	}
 	return res;
 }
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 733a033..aa4bc62 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -454,10 +454,8 @@ static int check_option(const char *haystack, size_t len,
 		size_t plen = sep ? (size_t) (sep - p) :
 				    len - (p - haystack);
 
-		if (plen == needle_len) {
-			if (!strncmp(p, needle, plen))
-				return !no;	/* foo or nofoo was found */
-		}
+		if (plen == needle_len && !strncmp(p, needle, plen))
+			return !no;	/* foo or nofoo was found */
 		p += plen;
 	}
 
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index 38ea161..fdbda7c 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -1105,10 +1105,8 @@ int main(int argc, char **argv)
 		}
 
 		signum = sigtimedwait(&set, NULL, &sigwait);
-		if (signum != SIGCHLD) {
-			if (signum < 0 && errno == EAGAIN)
-				break;
-		}
+		if (signum != SIGCHLD && signum < 0 && errno == EAGAIN)
+			break;
 
 	} while (1);
 
diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index 1849a4e..cf8a50d 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -394,9 +394,8 @@ int main(int argc, char **argv)
 		in = dump(in, filename, follow, out);
 	}
 
-	if (out != stdout)
-		if (close_stream(out))
-			err(EXIT_FAILURE, _("write failed"));
+	if (out != stdout && close_stream(out))
+		err(EXIT_FAILURE, _("write failed"));
 
 	if (in && in != stdin)
 		fclose(in);
diff --git a/login-utils/vipw.c b/login-utils/vipw.c
index 2e343b6..d12ea73 100644
--- a/login-utils/vipw.c
+++ b/login-utils/vipw.c
@@ -354,10 +354,9 @@ int main(int argc, char *argv[])
 		 * which means they can be translated. */
 		printf(_("Would you like to edit %s now [y/n]? "), orig_file);
 
-		if (fgets(response, sizeof(response), stdin)) {
-			if (rpmatch(response) == RPMATCH_YES)
-				edit_file(1);
-		}
+		if (fgets(response, sizeof(response), stdin) &&
+		    rpmatch(response) == RPMATCH_YES)
+			edit_file(1);
 	}
 	exit(EXIT_SUCCESS);
 }
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 2808793..ee8fafb 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -892,10 +892,8 @@ static int week_number(int day, int month, int32_t year, const struct cal_contro
 		month = JANUARY;
 
 	yday = day_in_year(day,month,year);
-	if (year == REFORMATION_YEAR) {
-		if (yday >= YDAY_AFTER_MISSING)
-			fday -= NUMBER_MISSING_DAYS;
-	}
+	if (year == REFORMATION_YEAR && yday >= YDAY_AFTER_MISSING)
+		fday -= NUMBER_MISSING_DAYS;
 
 	/* Last year is last year */
 	if (yday + fday < DAYS_IN_WEEK)
diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c
index f26d4d2..ffeb36a 100644
--- a/misc-utils/mcookie.c
+++ b/misc-utils/mcookie.c
@@ -121,10 +121,8 @@ static void randomness_from_files(struct mcookie_control *ctl)
 					   "Got %zu bytes from %s\n", count),
 					count, fname);
 
-			if (fd != STDIN_FILENO)
-				if (close(fd))
-					err(EXIT_FAILURE,
-					    _("closing %s failed"), fname);
+			if (fd != STDIN_FILENO && close(fd))
+				err(EXIT_FAILURE, _("closing %s failed"), fname);
 		}
 	}
 }
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 4b1782a..a3fe830 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -371,9 +371,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
 			if (ftruncate(fd_pidfile, 0))
 				err(EXIT_FAILURE, _("could not truncate file: %s"), pidfile_path);
 			write_all(fd_pidfile, reply_buf, strlen(reply_buf));
-			if (fd_pidfile > 1)
-				if (close_fd(fd_pidfile) != 0) /* Unlock the pid file */
-					err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
+			if (fd_pidfile > 1 && close_fd(fd_pidfile) != 0)
+				err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
 		}
 
 	}
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 36c966f..4544388 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1116,8 +1116,6 @@ static int parse_kmsg_record(struct dmesg_control *ctl,
 
 	/* D) optional fields (ignore) */
 	p = skip_item(p, end, ";");
-	if (LAST_KMSG_FIELD(p))
-		goto mesg;
 
 mesg:
 	/* E) message text */
@@ -1391,12 +1389,11 @@ int main(int argc, char *argv[])
 	if (argc > 1)
 		usage(stderr);
 
-	if (is_timefmt(&ctl, RELTIME) ||
-	    is_timefmt(&ctl, CTIME) ||
-	    is_timefmt(&ctl, ISO8601)) {
-		if (dmesg_get_boot_time(&ctl.boot_time) != 0)
-			ctl.time_fmt = DMESG_TIMEFTM_NONE;
-	}
+	if ((is_timefmt(&ctl, RELTIME) ||
+	     is_timefmt(&ctl, CTIME)   ||
+	     is_timefmt(&ctl, ISO8601))
+	    && dmesg_get_boot_time(&ctl.boot_time) != 0)
+		ctl.time_fmt = DMESG_TIMEFTM_NONE;
 
 	if (delta)
 		switch (ctl.time_fmt) {
diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index 0b40f15..7912fee 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -407,9 +407,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (rm_all)
-		if (remove_all(what_all))
-			ret++;
+	if (rm_all && remove_all(what_all))
+		ret++;
 
 	/* print usage if we still have some arguments left over */
 	if (optind < argc) {
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index 72894ea..053baf5 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -501,12 +501,9 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (ctl.clock_mode == CM_AUTO) {
-		if (read_clock_mode(&ctl) < 0) {
-			printf(_("%s: assuming RTC uses UTC ...\n"),
-					program_invocation_short_name);
-			ctl.clock_mode = CM_UTC;
-		}
+	if (ctl.clock_mode == CM_AUTO && read_clock_mode(&ctl) < 0) {
+		printf(_("%s: assuming RTC uses UTC ...\n"),  program_invocation_short_name);
+		ctl.clock_mode = CM_UTC;
 	}
 
 	if (ctl.verbose)
diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c
index 1630122..3b99a17 100644
--- a/sys-utils/setpriv.c
+++ b/sys-utils/setpriv.c
@@ -781,9 +781,8 @@ int main(int argc, char **argv)
 		errx(EXIT_FAILURE,
 		     _("--[re]gid requires --keep-groups, --clear-groups, or --groups"));
 
-	if (opts.nnp)
-		if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
-			err(EXIT_FAILURE, _("disallow granting new privileges failed"));
+	if (opts.nnp && prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
+		err(EXIT_FAILURE, _("disallow granting new privileges failed"));
 
 	if (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"));
 	}
 
-	if (opts.have_securebits)
-		if (prctl(PR_SET_SECUREBITS, opts.securebits, 0, 0, 0) != 0)
-			err(SETPRIV_EXIT_PRIVERR, _("set process securebits failed"));
+	if (opts.have_securebits && prctl(PR_SET_SECUREBITS, opts.securebits, 0, 0, 0) != 0)
+		err(SETPRIV_EXIT_PRIVERR, _("set process securebits failed"));
 
 	if (opts.bounding_set) {
 		do_caps(CAPNG_BOUNDING_SET, opts.bounding_set);
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index bb089df..bae97ff 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -109,10 +109,8 @@ int main(int argc, char **argv)
 		/* cannot happen */
 		err(EXIT_FAILURE, _("setsid failed"));
 
-	if (ctty) {
-		if (ioctl(STDIN_FILENO, TIOCSCTTY, 1))
-			err(EXIT_FAILURE, _("failed to set the controlling terminal"));
-	}
+	if (ctty && ioctl(STDIN_FILENO, TIOCSCTTY, 1))
+		err(EXIT_FAILURE, _("failed to set the controlling terminal"));
 	execvp(argv[optind], argv + optind);
 	err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
 }
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index f3fc667..d5d9a91 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -502,21 +502,16 @@ int main(int argc, char **argv)
 
 	login_argv[login_argc] = NULL;	/* last login argv */
 
-	if (options.chroot) {
-		if (chroot(options.chroot) < 0)
-			log_err(_("%s: can't change root directory %s: %m"),
-				options.tty, options.chroot);
-	}
-	if (options.chdir) {
-		if (chdir(options.chdir) < 0)
-			log_err(_("%s: can't change working directory %s: %m"),
-				options.tty, options.chdir);
-	}
-	if (options.nice) {
-		if (nice(options.nice) < 0)
-			log_warn(_("%s: can't change process priority: %m"),
-				options.tty);
-	}
+	if (options.chroot && chroot(options.chroot) < 0)
+		log_err(_("%s: can't change root directory %s: %m"),
+			options.tty, options.chroot);
+	if (options.chdir && chdir(options.chdir) < 0)
+		log_err(_("%s: can't change working directory %s: %m"),
+			options.tty, options.chdir);
+	if (options.nice && nice(options.nice) < 0)
+		log_warn(_("%s: can't change process priority: %m"),
+			 options.tty);
+
 	free(options.osrelease);
 #ifdef DEBUGGING
 	if (close_stream(dbf) != 0)
diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 13836e9..704fc59 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -809,11 +809,9 @@ static void screendump(struct setterm_control *ctl)
 /* Some options are applicable when terminal is virtual console. */
 static int vc_only(struct setterm_control *ctl, const char *err)
 {
-	if (!ctl->vcterm) {
-		if (err)
-			warnx(_("terminal %s does not support %s"),
-			      ctl->opt_te_terminal_name, err);
-	}
+	if (!ctl->vcterm && err)
+		warnx(_("terminal %s does not support %s"),
+		      ctl->opt_te_terminal_name, err);
 	return ctl->vcterm;
 }
 
diff --git a/text-utils/hexdump-parse.c b/text-utils/hexdump-parse.c
index 9eb016d..c60a4d0 100644
--- a/text-utils/hexdump-parse.c
+++ b/text-utils/hexdump-parse.c
@@ -460,15 +460,12 @@ isint:				cs[3] = '\0';
 			fs->bcnt < hex->blocksize &&
 			!(fu->flags&F_SETREP) && fu->bcnt)
 				fu->reps += (hex->blocksize - fs->bcnt) / fu->bcnt;
-		if (fu->reps > 1) {
-			if (!list_empty(&fu->prlist)) {
-				pr = list_last_entry(&fu->prlist,
-				  struct hexdump_pr, prlist);
-				for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
-					p2 = isspace(*p1) ? p1 : NULL;
-				if (p2)
-					pr->nospace = p2;
-			}
+		if (fu->reps > 1 && !list_empty(&fu->prlist)) {
+			pr = list_last_entry(&fu->prlist, struct hexdump_pr, prlist);
+			for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
+				p2 = isspace(*p1) ? p1 : NULL;
+			if (p2)
+				pr->nospace = p2;
 		}
 	}
 }
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index 6219aa2..4ca5c16 100644
--- a/text-utils/tailf.c
+++ b/text-utils/tailf.c
@@ -74,11 +74,9 @@ static void tailf(const char *filename, size_t lines, struct stat *st)
 	if (data[i] == '\n')
 		lines++;
 	while (i) {
-		if (data[i] == '\n') {
-			if (--lines == 0) {
-				i++;
-				break;
-			}
+		if (data[i] == '\n' && --lines == 0) {
+			i++;
+			break;
 		}
 		i--;
 	}
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/13] switch_root: simplify code and reduce indentation [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
  2016-07-17 13:00 ` [PATCH 01/13] misc: simplify if clauses [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 03/13] libfdisk: collapse " Sami Kerola
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

The if statement in line 162 already ensures value of cfd to be 0 or
greater, so the later if is not needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/switch_root.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index dc55a6d..6f5468f 100644
--- a/sys-utils/switch_root.c
+++ b/sys-utils/switch_root.c
@@ -176,22 +176,21 @@ static int switchroot(const char *newroot)
 		return -1;
 	}
 
-	if (cfd >= 0) {
-		pid = fork();
-		if (pid <= 0) {
-			struct statfs stfs;
-			if (fstatfs(cfd, &stfs) == 0 &&
-			    (F_TYPE_EQUAL(stfs.f_type, STATFS_RAMFS_MAGIC) ||
-			     F_TYPE_EQUAL(stfs.f_type, STATFS_TMPFS_MAGIC)))
-				recursiveRemove(cfd);
-			else
-				warn(_("old root filesystem is not an initramfs"));
-
-			if (pid == 0)
-				exit(EXIT_SUCCESS);
-		}
-		close(cfd);
+	pid = fork();
+	if (pid <= 0) {
+		struct statfs stfs;
+
+		if (fstatfs(cfd, &stfs) == 0 &&
+		    (F_TYPE_EQUAL(stfs.f_type, STATFS_RAMFS_MAGIC) ||
+		     F_TYPE_EQUAL(stfs.f_type, STATFS_TMPFS_MAGIC)))
+			recursiveRemove(cfd);
+		else
+			warn(_("old root filesystem is not an initramfs"));
+		if (pid == 0)
+			exit(EXIT_SUCCESS);
 	}
+
+	close(cfd);
 	return 0;
 }
 
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/13] libfdisk: collapse indentation [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
  2016-07-17 13:00 ` [PATCH 01/13] misc: simplify if clauses [oclint] Sami Kerola
  2016-07-17 13:00 ` [PATCH 02/13] switch_root: simplify code and reduce indentation [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-19  8:48   ` Karel Zak
  2016-07-17 13:00 ` [PATCH 04/13] lslogins: simplify if clause and move definition and comments [oclint] Sami Kerola
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Move conditionals to be together to avoid code blocks that are length of
full logical segment.  This allows fewer indentation steps, and improves
general readability.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libfdisk/src/sun.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c
index 55ec877..902596e 100644
--- a/libfdisk/src/sun.c
+++ b/libfdisk/src/sun.c
@@ -399,7 +399,8 @@ static int verify_sun_cmp(int *a, int *b, void *data)
 static int sun_verify_disklabel(struct fdisk_context *cxt)
 {
     uint32_t starts[SUN_MAXPARTITIONS], lens[SUN_MAXPARTITIONS], start, stop;
-    uint32_t i,j,k,starto,endo;
+    uint32_t i, j, k, starto, endo;
+
 #ifdef HAVE_QSORT_R
     int array[SUN_MAXPARTITIONS];
     unsigned int *verify_sun_starts;
@@ -413,30 +414,29 @@ static int sun_verify_disklabel(struct fdisk_context *cxt)
     for (k = 0; k < 7; k++) {
 	for (i = 0; i < SUN_MAXPARTITIONS; i++) {
 	    if (k && (lens[i] % (cxt->geom.heads * cxt->geom.sectors)))
-	        fdisk_warnx(cxt, _("Partition %u doesn't end on cylinder boundary."), i+1);
+		fdisk_warnx(cxt, _("Partition %u doesn't end on cylinder boundary."), i + 1);
 	    if (lens[i]) {
-	        for (j = 0; j < i; j++)
-	            if (lens[j]) {
-	                if (starts[j] == starts[i]+lens[i]) {
-	                    starts[j] = starts[i]; lens[j] += lens[i];
-	                    lens[i] = 0;
-	                } else if (starts[i] == starts[j]+lens[j]){
-	                    lens[j] += lens[i];
-	                    lens[i] = 0;
-	                } else if (!k) {
-	                    if (starts[i] < starts[j]+lens[j] &&
-				starts[j] < starts[i]+lens[i]) {
-	                        starto = starts[i];
-	                        if (starts[j] > starto)
-					starto = starts[j];
-	                        endo = starts[i]+lens[i];
-	                        if (starts[j]+lens[j] < endo)
-					endo = starts[j]+lens[j];
-	                        fdisk_warnx(cxt, _("Partition %u overlaps with others in "
-				       "sectors %u-%u."), i+1, starto, endo);
-	                    }
-	                }
-	            }
+		for (j = 0; j < i && lens[j]; j++)
+		    if (starts[j] == starts[i] + lens[i]) {
+			starts[j] = starts[i];
+			lens[j] += lens[i];
+			lens[i] = 0;
+		    } else if (starts[i] == starts[j] + lens[j]) {
+			lens[j] += lens[i];
+			lens[i] = 0;
+		    } else if (!k &&
+			       starts[i] < starts[j] + lens[j] &&
+			       starts[j] < starts[i] + lens[i]) {
+			starto = starts[i];
+			if (starts[j] > starto)
+			    starto = starts[j];
+			endo = starts[i] + lens[i];
+			if (starts[j] + lens[j] < endo)
+			    endo = starts[j] + lens[j];
+			fdisk_warnx(cxt,
+				    _("Partition %u overlaps with others in "
+				      "sectors %u-%u."), i + 1, starto, endo);
+		    }
 	    }
 	}
     }
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/13] lslogins: simplify if clause and move definition and comments [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (2 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 03/13] libfdisk: collapse " Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 05/13] libblkid: simplify if clause [oclint] Sami Kerola
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

The if clause change is pretty trivial.  Moving the macro near to where it
is used makes sense to people who want to read the code.  And finally the
comment about user list was at wrong spot.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/lslogins.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 3ff7725..60a1b50 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -766,14 +766,6 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
 	return user;
 }
 
-/* some UNIX implementations set errno iff a passwd/grp/...
- * entry was not found. The original UNIX logins(1) utility always
- * ignores invalid login/group names, so we're going to as well.*/
-#define IS_REAL_ERRNO(e) !((e) == ENOENT || (e) == ESRCH || \
-		(e) == EBADF || (e) == EPERM || (e) == EAGAIN)
-
-/* get a definitive list of users we want info about... */
-
 static int str_to_uint(char *s, unsigned int *ul)
 {
 	char *end;
@@ -785,6 +777,7 @@ static int str_to_uint(char *s, unsigned int *ul)
 	return 1;
 }
 
+/* get a definitive list of users we want info about... */
 static int get_ulist(struct lslogins_control *ctl, char *logins, char *groups)
 {
 	char *u, *g;
@@ -878,13 +871,18 @@ static struct lslogins_user *get_next_user(struct lslogins_control *ctl)
 	return u;
 }
 
+/* some UNIX implementations set errno iff a passwd/grp/...
+ * entry was not found. The original UNIX logins(1) utility always
+ * ignores invalid login/group names, so we're going to as well.*/
+#define IS_REAL_ERRNO(e) !((e) == ENOENT || (e) == ESRCH || \
+		(e) == EBADF || (e) == EPERM || (e) == EAGAIN)
+
 static int get_user(struct lslogins_control *ctl, struct lslogins_user **user,
 		    const char *username)
 {
 	*user = get_user_info(ctl, username);
-	if (!*user)
-		if (IS_REAL_ERRNO(errno))
-			return -1;
+	if (!*user && IS_REAL_ERRNO(errno))
+		return -1;
 	return 0;
 }
 
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/13] libblkid: simplify if clause [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (3 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 04/13] lslogins: simplify if clause and move definition and comments [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 06/13] logger: " Sami Kerola
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Move negative and positive testing of 'has' variable to top level, and test
flag bit mask on second level.  This way the 'has' needs to be checked only
once.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libblkid/src/probe.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index d7a3ba7..43ea4c7 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -552,13 +552,11 @@ int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[
 				break;
 			}
 		}
-		if (flag & BLKID_FLTR_ONLYIN) {
-		       if (!has)
+		if (has) {
+			if (flag & BLKID_FLTR_NOTIN)
 				blkid_bmp_set_item(fltr, i);
-		} else if (flag & BLKID_FLTR_NOTIN) {
-			if (has)
-				blkid_bmp_set_item(fltr, i);
-		}
+		} else if (flag & BLKID_FLTR_ONLYIN)
+			blkid_bmp_set_item(fltr, i);
 	}
 
 	DBG(LOWPROBE, ul_debug("%s: a new probing type-filter initialized",
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/13] logger: simplify if clause [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (4 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 05/13] libblkid: simplify if clause [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 07/13] syspriv: flip inverted logic [oclint] Sami Kerola
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

This has effect of collapsing rather long indentation block, so commit
separately.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/logger.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 9f2940c..8a1f7d6 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -927,32 +927,32 @@ static void logger_stdin(struct logger_ctl *ctl)
 	c = getchar();
 	while (c != EOF) {
 		i = 0;
-		if (ctl->prio_prefix) {
-			if (c == '<') {
-				pri = 0;
+		if (ctl->prio_prefix && c == '<') {
+			pri = 0;
+			buf[i++] = c;
+			while (isdigit(c = getchar()) && pri <= 191) {
+				buf[i++] = c;
+				pri = pri * 10 + c - '0';
+			}
+			if (c != EOF && c != '\n')
 				buf[i++] = c;
-				while (isdigit(c = getchar()) && pri <= 191) {
-					buf[i++] = c;
-					pri = pri * 10 + c - '0';
-				}
-				if (c != EOF && c != '\n')
-					buf[i++] = c;
-				if (c == '>' && 0 <= pri && pri <= 191) { /* valid RFC PRI values */
-					i = 0;
-					if (pri < 8)
-						pri |= 8; /* kern facility is forbidden */
-					ctl->pri = pri;
-				} else
-					ctl->pri = default_priority;
-
-				if (ctl->pri != last_pri) {
-					has_header = 0;
-					max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
-					last_pri = ctl->pri;
-				}
-				if (c != EOF && c != '\n')
-					c = getchar();
+			if (c == '>' && 0 <= pri && pri <= 191) {
+				/* valid RFC PRI values */
+				i = 0;
+				if (pri < 8)	/* kern facility is forbidden */
+					pri |= 8;
+				ctl->pri = pri;
+			} else
+				ctl->pri = default_priority;
+
+			if (ctl->pri != last_pri) {
+				has_header = 0;
+				max_usrmsg_size =
+				    ctl->max_message_size - strlen(ctl->hdr);
+				last_pri = ctl->pri;
 			}
+			if (c != EOF && c != '\n')
+				c = getchar();
 		}
 
 		while (c != EOF && c != '\n' && i < max_usrmsg_size) {
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/13] syspriv: flip inverted logic [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (5 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 06/13] logger: " Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 08/13] libmount, look: remove dead code [oclint] Sami Kerola
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/setpriv.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c
index 3b99a17..977ccd1 100644
--- a/sys-utils/setpriv.c
+++ b/sys-utils/setpriv.c
@@ -175,10 +175,10 @@ static int print_caps(FILE *f, capng_type_t which)
 static void dump_one_secbit(int *first, int *bits, int bit, const char *name)
 {
 	if (*bits & bit) {
-		if (!*first)
-			printf(",");
-		else
+		if (*first)
 			*first = 0;
+		else
+			printf(",");
 		fputs(name, stdout);
 		*bits &= ~bit;
 	}
@@ -206,10 +206,10 @@ static void dump_securebits(void)
 	dump_one_secbit(&first, &bits, SECBIT_KEEP_CAPS_LOCKED,
 			"keep_caps_locked");
 	if (bits) {
-		if (!first)
-			printf(",");
-		else
+		if (first)
 			first = 0;
+		else
+			printf(",");
 		printf("0x%x", (unsigned)bits);
 	}
 
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/13] libmount, look: remove dead code [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (6 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 07/13] syspriv: flip inverted logic [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 09/13] dmesg: drop core at impossible case in read_buffer() [oclint] Sami Kerola
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libmount/src/context_mount.c  | 1 -
 libmount/src/context_umount.c | 1 -
 misc-utils/look.c             | 2 --
 3 files changed, 4 deletions(-)

diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index 7e5128b..91611ef 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -566,7 +566,6 @@ int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg)
 		break;
 	default:
 		return 1;
-		break;
 	}
 
 	return rc;
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 707665d..d003c5d 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -620,7 +620,6 @@ int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg)
 		break;
 	default:
 		return 1;
-		break;
 	}
 
 	return rc;
diff --git a/misc-utils/look.c b/misc-utils/look.c
index f0cc1d7..93c388e 100644
--- a/misc-utils/look.c
+++ b/misc-utils/look.c
@@ -274,10 +274,8 @@ linear_search(char *front, char *back)
 		switch (compare(front, back)) {
 		case EQUAL:		/* Found it. */
 			return (front);
-			break;
 		case LESS:		/* No such string. */
 			return (NULL);
-			break;
 		case GREATER:		/* Keep going. */
 			break;
 		}
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/13] dmesg: drop core at impossible case in read_buffer() [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (7 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 08/13] libmount, look: remove dead code [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 10/13] misc: fix declarations shadowing variables in the global scope [oclint] Sami Kerola
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/dmesg.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 4544388..92de6e2 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -591,6 +591,8 @@ static ssize_t read_buffer(struct dmesg_control *ctl, char **buf)
 		if (n == 0 && ctl->action == SYSLOG_ACTION_READ_CLEAR)
 			n = klogctl(SYSLOG_ACTION_CLEAR, NULL, 0);
 		break;
+	default:
+		abort();	/* impossible method -> drop core */
 	}
 
 	return n;
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/13] misc: fix declarations shadowing variables in the global scope [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (8 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 09/13] dmesg: drop core at impossible case in read_buffer() [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 11/13] setterm: " Sami Kerola
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Fixes multiple occurences of 'optarg' overwrites.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/last.c     |  6 +++---
 login-utils/lslogins.c |  6 +++---
 misc-utils/logger.c    | 14 +++++++-------
 sys-utils/dmesg.c      | 14 +++++++-------
 sys-utils/ipcrm.c      |  8 ++++----
 sys-utils/lsipc.c      |  6 +++---
 sys-utils/rtcwake.c    |  6 +++---
 7 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 0c234f5..6d0e892 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -163,15 +163,15 @@ static time_t lastdate;		/* Last date we've seen */
 static time_t currentdate;	/* date when we started processing the file */
 
 /* --time-format=option parser */
-static int which_time_format(const char *optarg)
+static int which_time_format(const char *s)
 {
 	size_t i;
 
 	for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
-		if (strcmp(timefmts[i].name, optarg) == 0)
+		if (strcmp(timefmts[i].name, s) == 0)
 			return i;
 	}
-	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+	errx(EXIT_FAILURE, _("unknown time format: %s"), s);
 }
 
 /*
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 60a1b50..76ada7f 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -1200,7 +1200,7 @@ static void free_user(void *f)
 	free(u);
 }
 
-static int parse_time_mode(const char *optarg)
+static int parse_time_mode(const char *s)
 {
 	struct lslogins_timefmt {
 		const char *name;
@@ -1214,10 +1214,10 @@ static int parse_time_mode(const char *optarg)
 	size_t i;
 
 	for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
-		if (strcmp(timefmts[i].name, optarg) == 0)
+		if (strcmp(timefmts[i].name, s) == 0)
 			return timefmts[i].val;
 	}
-	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+	errx(EXIT_FAILURE, _("unknown time format: %s"), s);
 }
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 8a1f7d6..5b43566 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -807,11 +807,11 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl)
 	free(structured);
 }
 
-static void parse_rfc5424_flags(struct logger_ctl *ctl, char *optarg)
+static void parse_rfc5424_flags(struct logger_ctl *ctl, char *s)
 {
 	char *in, *tok;
 
-	in = optarg;
+	in = s;
 	while ((tok = strtok(in, ","))) {
 		in = NULL;
 		if (!strcmp(tok, "notime")) {
@@ -826,15 +826,15 @@ static void parse_rfc5424_flags(struct logger_ctl *ctl, char *optarg)
 	}
 }
 
-static int parse_unix_socket_errors_flags(char *optarg)
+static int parse_unix_socket_errors_flags(char *s)
 {
-	if (!strcmp(optarg, "off"))
+	if (!strcmp(s, "off"))
 		return AF_UNIX_ERRORS_OFF;
-	if (!strcmp(optarg, "on"))
+	if (!strcmp(s, "on"))
 		return AF_UNIX_ERRORS_ON;
-	if (!strcmp(optarg, "auto"))
+	if (!strcmp(s, "auto"))
 		return AF_UNIX_ERRORS_AUTO;
-	warnx(_("invalid argument: %s: using automatic errors"), optarg);
+	warnx(_("invalid argument: %s: using automatic errors"), s);
 	return AF_UNIX_ERRORS_AUTO;
 }
 
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 92de6e2..a2ab3a2 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1178,19 +1178,19 @@ static int read_kmsg(struct dmesg_control *ctl)
 	return 0;
 }
 
-static int which_time_format(const char *optarg)
+static int which_time_format(const char *s)
 {
-	if (!strcmp(optarg, "notime"))
+	if (!strcmp(s, "notime"))
 		return DMESG_TIMEFTM_NONE;
-	if (!strcmp(optarg, "ctime"))
+	if (!strcmp(s, "ctime"))
 		return DMESG_TIMEFTM_CTIME;
-	if (!strcmp(optarg, "delta"))
+	if (!strcmp(s, "delta"))
 		return DMESG_TIMEFTM_DELTA;
-	if (!strcmp(optarg, "reltime"))
+	if (!strcmp(s, "reltime"))
 		return DMESG_TIMEFTM_RELTIME;
-	if (!strcmp(optarg, "iso"))
+	if (!strcmp(s, "iso"))
 		return DMESG_TIMEFTM_ISO8601;
-	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+	errx(EXIT_FAILURE, _("unknown time format: %s"), s);
 }
 
 #ifdef TEST_DMESG
diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index 7912fee..06bbd44 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -191,13 +191,13 @@ static unsigned long strtokey(const char *str, const char *errmesg)
 	return 0;
 }
 
-static int key_to_id(type_id type, char *optarg)
+static int key_to_id(type_id type, char *s)
 {
 	int id;
 	/* keys are in hex or decimal */
-	key_t key = strtokey(optarg, "failed to parse argument");
+	key_t key = strtokey(s, "failed to parse argument");
 	if (key == IPC_PRIVATE) {
-		warnx(_("illegal key (%s)"), optarg);
+		warnx(_("illegal key (%s)"), s);
 		return -1;
 	}
 	switch (type) {
@@ -230,7 +230,7 @@ static int key_to_id(type_id type, char *optarg)
 		default:
 			err(EXIT_FAILURE, _("key failed"));
 		}
-		warnx("%s (%s)", errmsg, optarg);
+		warnx("%s (%s)", errmsg, s);
 	}
 	return id;
 }
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 9041dc1..d4e5037 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -249,7 +249,7 @@ static char *get_groupname(struct group **gr, gid_t id)
 	return *gr ? xstrdup((*gr)->gr_name) : NULL;
 }
 
-static int parse_time_mode(const char *optarg)
+static int parse_time_mode(const char *s)
 {
 	struct lsipc_timefmt {
 		const char *name;
@@ -263,10 +263,10 @@ static int parse_time_mode(const char *optarg)
 	size_t i;
 
 	for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
-		if (strcmp(timefmts[i].name, optarg) == 0)
+		if (strcmp(timefmts[i].name, s) == 0)
 			return timefmts[i].val;
 	}
-	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+	errx(EXIT_FAILURE, _("unknown time format: %s"), s);
 }
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index 053baf5..536c5bf 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -344,18 +344,18 @@ static int print_alarm(struct rtcwake_control *ctl, int fd)
 	return 0;
 }
 
-static int get_rtc_mode(struct rtcwake_control *ctl, const char *optarg)
+static int get_rtc_mode(struct rtcwake_control *ctl, const char *s)
 {
 	size_t i;
 	char **modes = get_sys_power_states(ctl), **m;
 
 	STRV_FOREACH(m, modes) {
-		if (strcmp(optarg, *m) == 0)
+		if (strcmp(s, *m) == 0)
 			return SYSFS_MODE;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(rtcwake_mode_string); i++)
-		if (!strcmp(optarg, rtcwake_mode_string[i]))
+		if (!strcmp(s, rtcwake_mode_string[i]))
 			return i;
 
 	return -EINVAL;
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/13] setterm: fix declarations shadowing variables in the global scope [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (9 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 10/13] misc: fix declarations shadowing variables in the global scope [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 12/13] agetty: move unreachable code to pre-processor #else segment [oclint] Sami Kerola
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/setterm.c | 80 ++++++++++++++++++++++++++--------------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 704fc59..e2c627a 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -217,18 +217,18 @@ static int parse_febg_color(const char *arg)
 	return color;
 }
 
-static int parse_ulhb_color(char **argv, int *optind)
+static int parse_ulhb_color(char **av, int *oi)
 {
 	char *color_name;
 	int bright = 0;
 	int color = -1;
 
-	if (argv[*optind] && strcmp(argv[*optind - 1], "bright") == 0) {
+	if (av[*oi] && strcmp(av[*oi - 1], "bright") == 0) {
 		bright = 1;
-		color_name = argv[*optind];
-		(*optind)++;
+		color_name = av[*oi];
+		(*oi)++;
 	} else
-		color_name = argv[*optind - 1];
+		color_name = av[*oi - 1];
 
 	color = parse_color(color_name);
 	if (color < 0)
@@ -241,25 +241,25 @@ static int parse_ulhb_color(char **argv, int *optind)
 	return color;
 }
 
-static char *find_optional_arg(char **argv, char *optarg, int *optind)
+static char *find_optional_arg(char **av, char *oa, int *oi)
 {
 	char *arg;
-	if (optarg)
-		return optarg;
+	if (oa)
+		return oa;
 	else {
-		arg = argv[*optind];
+		arg = av[*oi];
 		if (!arg || arg[0] == '-')
 			return NULL;
 	}
-	(*optind)++;
+	(*oi)++;
 	return arg;
 }
 
-static int parse_blank(char **argv, char *optarg, int *optind)
+static int parse_blank(char **av, char *oa, int *oi)
 {
 	char *arg;
 
-	arg = find_optional_arg(argv, optarg, optind);
+	arg = find_optional_arg(av, oa, oi);
 	if (!arg)
 		return BLANKEDSCREEN;
 	if (!strcmp(arg, "force"))
@@ -301,12 +301,12 @@ static int parse_msglevel(const char *arg)
 	return ret;
 }
 
-static int parse_snap(char **argv, char *optarg, int *optind)
+static int parse_snap(char **av, char *oa, int *oi)
 {
 	int ret;
 	char *arg;
 
-	arg = find_optional_arg(argv, optarg, optind);
+	arg = find_optional_arg(av, oa, oi);
 	if (!arg)
 		return 0;
 	ret = strtos32_or_err(arg, _("argument error"));
@@ -315,32 +315,32 @@ static int parse_snap(char **argv, char *optarg, int *optind)
 	return ret;
 }
 
-static void parse_tabs(char **argv, char *optarg, int *optind, int *tab_array)
+static void parse_tabs(char **av, char *oa, int *oi, int *tab_array)
 {
 	int i = 0;
 
-	if (optarg) {
-		tab_array[i] = strtos32_or_err(optarg, _("argument error"));
+	if (oa) {
+		tab_array[i] = strtos32_or_err(oa, _("argument error"));
 		i++;
 	}
-	while (argv[*optind]) {
+	while (av[*oi]) {
 		if (TABS_MAX < i)
 			errx(EXIT_FAILURE, _("too many tabs"));
-		if (argv[*optind][0] == '-')
+		if (av[*oi][0] == '-')
 			break;
-		tab_array[i] = strtos32_or_err(argv[*optind], _("argument error"));
-		(*optind)++;
+		tab_array[i] = strtos32_or_err(av[*oi], _("argument error"));
+		(*oi)++;
 		i++;
 	}
 	tab_array[i] = -1;
 }
 
-static int parse_regtabs(char **argv, char *optarg, int *optind)
+static int parse_regtabs(char **av, char *oa, int *oi)
 {
 	int ret;
 	char *arg;
 
-	arg = find_optional_arg(argv, optarg, optind);
+	arg = find_optional_arg(av, oa, oi);
 	if (!arg)
 		return DEFAULT_TAB_LEN;
 	ret = strtos32_or_err(arg, _("argument error"));
@@ -349,12 +349,12 @@ static int parse_regtabs(char **argv, char *optarg, int *optind)
 	return ret;
 }
 
-static int parse_blength(char **argv, char *optarg, int *optind)
+static int parse_blength(char **av, char *oa, int *oi)
 {
 	int ret = -1;
 	char *arg;
 
-	arg = find_optional_arg(argv, optarg, optind);
+	arg = find_optional_arg(av, oa, oi);
 	if (!arg)
 		return 0;
 	ret = strtos32_or_err(arg, _("argument error"));
@@ -363,11 +363,11 @@ static int parse_blength(char **argv, char *optarg, int *optind)
 	return ret;
 }
 
-static int parse_bfreq(char **argv, char *optarg, int *optind)
+static int parse_bfreq(char **av, char *oa, int *oi)
 {
 	char *arg;
 
-	arg = find_optional_arg(argv, optarg, optind);
+	arg = find_optional_arg(av, oa, oi);
 	if (!arg)
 		return 0;
 	return strtos32_or_err(arg, _("argument error"));
@@ -431,7 +431,7 @@ static int __attribute__((__pure__)) set_opt_flag(int opt)
 	return 1;
 }
 
-static void parse_option(struct setterm_control *ctl, int argc, char **argv)
+static void parse_option(struct setterm_control *ctl, int ac, char **av)
 {
 	int c;
 	enum {
@@ -517,7 +517,7 @@ static void parse_option(struct setterm_control *ctl, int argc, char **argv)
 	};
 	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
 
-	while ((c = getopt_long_only(argc, argv, "", longopts, NULL)) != -1) {
+	while ((c = getopt_long_only(ac, av, "", longopts, NULL)) != -1) {
 		err_exclusive_options(c, longopts, excl, excl_st);
 		switch (c) {
 		case OPT_TERM:
@@ -563,11 +563,11 @@ static void parse_option(struct setterm_control *ctl, int argc, char **argv)
 			break;
 		case OPT_ULCOLOR:
 			ctl->opt_ulcolor = set_opt_flag(ctl->opt_ulcolor);
-			ctl->opt_ul_color = parse_ulhb_color(argv, &optind);
+			ctl->opt_ul_color = parse_ulhb_color(av, &optind);
 			break;
 		case OPT_HBCOLOR:
 			ctl->opt_hbcolor = set_opt_flag(ctl->opt_hbcolor);
-			ctl->opt_hb_color = parse_ulhb_color(argv, &optind);
+			ctl->opt_hb_color = parse_ulhb_color(av, &optind);
 			break;
 		case OPT_INVERSESCREEN:
 			ctl->opt_inversescreen = set_opt_flag(ctl->opt_inversescreen);
@@ -609,27 +609,27 @@ static void parse_option(struct setterm_control *ctl, int argc, char **argv)
 			break;
 		case OPT_TABS:
 			ctl->opt_tabs = set_opt_flag(ctl->opt_tabs);
-			parse_tabs(argv, optarg, &optind, ctl->opt_tb_array);
+			parse_tabs(av, optarg, &optind, ctl->opt_tb_array);
 			break;
 		case OPT_CLRTABS:
 			ctl->opt_clrtabs = set_opt_flag(ctl->opt_clrtabs);
-			parse_tabs(argv, optarg, &optind, ctl->opt_tb_array);
+			parse_tabs(av, optarg, &optind, ctl->opt_tb_array);
 			break;
 		case OPT_REGTABS:
 			ctl->opt_regtabs = set_opt_flag(ctl->opt_regtabs);
-			ctl->opt_rt_len = parse_regtabs(argv, optarg, &optind);
+			ctl->opt_rt_len = parse_regtabs(av, optarg, &optind);
 			break;
 		case OPT_BLANK:
 			ctl->opt_blank = set_opt_flag(ctl->opt_blank);
-			ctl->opt_bl_min = parse_blank(argv, optarg, &optind);
+			ctl->opt_bl_min = parse_blank(av, optarg, &optind);
 			break;
 		case OPT_DUMP:
 			ctl->opt_snap = set_opt_flag(ctl->opt_snap);
-			ctl->opt_sn_num = parse_snap(argv, optarg, &optind);
+			ctl->opt_sn_num = parse_snap(av, optarg, &optind);
 			break;
 		case OPT_APPEND:
 			ctl->opt_append = set_opt_flag(ctl->opt_append);
-			ctl->opt_sn_num = parse_snap(argv, optarg, &optind);
+			ctl->opt_sn_num = parse_snap(av, optarg, &optind);
 			break;
 		case OPT_FILE:
 			ctl->opt_snapfile = set_opt_flag(ctl->opt_snapfile);
@@ -654,15 +654,15 @@ static void parse_option(struct setterm_control *ctl, int argc, char **argv)
 			break;
 		case OPT_POWERDOWN:
 			ctl->opt_powerdown = set_opt_flag(ctl->opt_powerdown);
-			ctl->opt_pd_min = parse_blank(argv, optarg, &optind);
+			ctl->opt_pd_min = parse_blank(av, optarg, &optind);
 			break;
 		case OPT_BLENGTH:
 			ctl->opt_blength = set_opt_flag(ctl->opt_blength);
-			ctl->opt_blength_l = parse_blength(argv, optarg, &optind);
+			ctl->opt_blength_l = parse_blength(av, optarg, &optind);
 			break;
 		case OPT_BFREQ:
 			ctl->opt_bfreq = set_opt_flag(ctl->opt_bfreq);
-			ctl->opt_bfreq_f = parse_bfreq(argv, optarg, &optind);
+			ctl->opt_bfreq_f = parse_bfreq(av, optarg, &optind);
 			break;
 		case OPT_VERSION:
 			printf(UTIL_LINUX_VERSION);
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 12/13] agetty: move unreachable code to pre-processor #else segment [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (10 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 11/13] setterm: " Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-07-17 13:00 ` [PATCH 13/13] libblkid: fix debugging macro [oclint] Sami Kerola
  2016-08-02 13:44 ` [PATCH 00/13] pull: OCLint static code analysis changes Karel Zak
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/agetty.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index d5d9a91..1089c77 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1424,7 +1424,7 @@ static char *xgetdomainname(void)
 {
 #ifdef HAVE_GETDOMAINNAME
 	char *name;
-	size_t sz = get_hostname_max() + 1;
+	const size_t sz = get_hostname_max() + 1;
 
 	name = malloc(sizeof(char) * sz);
 	if (!name)
@@ -1436,8 +1436,9 @@ static char *xgetdomainname(void)
 	}
 	name[sz - 1] = '\0';
 	return name;
-#endif
+#else
 	return NULL;
+#endif
 }
 
 static char *read_os_release(struct options *op, const char *varname)
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 13/13] libblkid: fix debugging macro [oclint]
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (11 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 12/13] agetty: move unreachable code to pre-processor #else segment [oclint] Sami Kerola
@ 2016-07-17 13:00 ` Sami Kerola
  2016-08-02 13:44 ` [PATCH 00/13] pull: OCLint static code analysis changes Karel Zak
  13 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-17 13:00 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

The oclint was complaining 'empty do/while statement' that turned out to be
true and I started to think it is best to use the same DBG() macro as in
other source files for this library.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libblkid/src/superblocks/zfs.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c
index f44fe52..b6ffac5 100644
--- a/libblkid/src/superblocks/zfs.c
+++ b/libblkid/src/superblocks/zfs.c
@@ -65,9 +65,6 @@ struct nvlist {
 	struct nvpair	nvl_nvpair;
 };
 
-#define nvdebug(fmt, ...)	do { } while(0)
-/*#define nvdebug(fmt, a...)	fprintf(stderr, fmt, ##a)*/
-
 static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 {
 	unsigned char *p, buff[4096];
@@ -90,7 +87,7 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 	memcpy(buff, p, sizeof(buff));
 	nvl = (struct nvlist *) buff;
 
-	nvdebug("zfs_extract: nvlist offset %llu\n", offset);
+	DBG(LOWPROBE, ul_debug("zfs_extract: nvlist offset %jd\n", offset));
 
 	nvp = &nvl->nvl_nvpair;
 	while (left > sizeof(*nvp) && nvp->nvp_size != 0 && found < 3) {
@@ -101,15 +98,15 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 		nvp->nvp_namelen = be32_to_cpu(nvp->nvp_namelen);
 		avail = nvp->nvp_size - nvp->nvp_namelen - sizeof(*nvp);
 
-		nvdebug("left %zd nvp_size %u\n", left, nvp->nvp_size);
+		DBG(LOWPROBE, ul_debug("left %zd nvp_size %u\n", left, nvp->nvp_size));
 		if (left < nvp->nvp_size || avail < 0)
 			break;
 
 		namesize = (nvp->nvp_namelen + 3) & ~3;
 
-		nvdebug("nvlist: size %u, namelen %u, name %*s\n",
+		DBG(LOWPROBE, ul_debug("nvlist: size %u, namelen %u, name %*s\n",
 			nvp->nvp_size, nvp->nvp_namelen, nvp->nvp_namelen,
-			nvp->nvp_name);
+			nvp->nvp_name));
 		if (strncmp(nvp->nvp_name, "name", nvp->nvp_namelen) == 0) {
 			struct nvstring *nvs = (void *)(nvp->nvp_name+namesize);
 
@@ -118,8 +115,8 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 			if (nvs->nvs_strlen > UINT_MAX - sizeof(*nvs))
 				break;
 			avail -= nvs->nvs_strlen + sizeof(*nvs);
-			nvdebug("nvstring: type %u string %*s\n", nvs->nvs_type,
-				nvs->nvs_strlen, nvs->nvs_string);
+			DBG(LOWPROBE, ul_debug("nvstring: type %u string %*s\n", nvs->nvs_type,
+				nvs->nvs_strlen, nvs->nvs_string));
 			if (nvs->nvs_type == DATA_TYPE_STRING && avail >= 0)
 				blkid_probe_set_label(pr, nvs->nvs_string,
 						      nvs->nvs_strlen);
@@ -133,8 +130,8 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 			nvu->nvu_type = be32_to_cpu(nvu->nvu_type);
 			nvu_value = be64_to_cpu(nvu_value);
 			avail -= sizeof(*nvu);
-			nvdebug("nvuint64: type %u value %"PRIu64"\n",
-				nvu->nvu_type, nvu_value);
+			DBG(LOWPROBE, ul_debug("nvuint64: type %u value %"PRIu64"\n",
+				nvu->nvu_type, nvu_value));
 			if (nvu->nvu_type == DATA_TYPE_UINT64 && avail >= 0)
 				blkid_probe_sprintf_value(pr, "UUID_SUB",
 							  "%"PRIu64, nvu_value);
@@ -148,8 +145,8 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 			nvu->nvu_type = be32_to_cpu(nvu->nvu_type);
 			nvu_value = be64_to_cpu(nvu_value);
 			avail -= sizeof(*nvu);
-			nvdebug("nvuint64: type %u value %"PRIu64"\n",
-				nvu->nvu_type, nvu_value);
+			DBG(LOWPROBE, ul_debug("nvuint64: type %u value %"PRIu64"\n",
+				nvu->nvu_type, nvu_value));
 			if (nvu->nvu_type == DATA_TYPE_UINT64 && avail >= 0)
 				blkid_probe_sprintf_uuid(pr, (unsigned char *)
 							 &nvu_value,
@@ -165,9 +162,6 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 	}
 }
 
-#define zdebug(fmt, ...)	do {} while(0)
-/*#define zdebug(fmt, a...)	fprintf(stderr, fmt, ##a)*/
-
 static int find_uberblocks(const void *label, loff_t *ub_offset, int *swap_endian)
 {
 	uint64_t swab_magic = swab64((uint64_t)UBERBLOCK_MAGIC);
@@ -182,14 +176,14 @@ static int find_uberblocks(const void *label, loff_t *ub_offset, int *swap_endia
 			*ub_offset = offset;
 			*swap_endian = 0;
 			found++;
-			zdebug("probe_zfs: found little-endian uberblock at %llu\n", offset >> 10);
+			DBG(LOWPROBE, ul_debug("probe_zfs: found little-endian uberblock at %jd\n", offset >> 10));
 		}
 
 		if (ub->ub_magic == swab_magic) {
 			*ub_offset = offset;
 			*swap_endian = 1;
 			found++;
-			zdebug("probe_zfs: found big-endian uberblock at %llu\n", offset >> 10);
+			DBG(LOWPROBE, ul_debug("probe_zfs: found big-endian uberblock at %jd\n", offset >> 10));
 		}
 	}
 
@@ -209,7 +203,7 @@ static int probe_zfs(blkid_probe pr,
 	void *label;
 	loff_t blk_align = (pr->size % (256 * 1024ULL));
 
-	zdebug("probe_zfs\n");
+	DBG(PROBE, ul_debug("probe_zfs\n"));
 	/* Look for at least 4 uberblocks to ensure a positive match */
 	for (label_no = 0; label_no < 4; label_no++) {
 		switch(label_no) {
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 03/13] libfdisk: collapse indentation [oclint]
  2016-07-17 13:00 ` [PATCH 03/13] libfdisk: collapse " Sami Kerola
@ 2016-07-19  8:48   ` Karel Zak
  2016-07-21 20:20     ` Sami Kerola
  0 siblings, 1 reply; 17+ messages in thread
From: Karel Zak @ 2016-07-19  8:48 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jul 17, 2016 at 02:00:05PM +0100, Sami Kerola wrote:
> -	        for (j = 0; j < i; j++)
> -	            if (lens[j]) {

> +		for (j = 0; j < i && lens[j]; j++)


 I don't think the result is the same logic.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 03/13] libfdisk: collapse indentation [oclint]
  2016-07-19  8:48   ` Karel Zak
@ 2016-07-21 20:20     ` Sami Kerola
  0 siblings, 0 replies; 17+ messages in thread
From: Sami Kerola @ 2016-07-21 20:20 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

On 19 July 2016 at 09:48, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Jul 17, 2016 at 02:00:05PM +0100, Sami Kerola wrote:
>> -             for (j = 0; j < i; j++)
>> -                 if (lens[j]) {
>
>> +             for (j = 0; j < i && lens[j]; j++)
>
>
>  I don't think the result is the same logic.

Oh I see. The patch is dropped from the my oclint branch, that is
rebased on top change 10e8d7a.

-- 
Sami Kerola
http://www.iki.fi/kerolasa/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 00/13] pull: OCLint static code analysis changes
  2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
                   ` (12 preceding siblings ...)
  2016-07-17 13:00 ` [PATCH 13/13] libblkid: fix debugging macro [oclint] Sami Kerola
@ 2016-08-02 13:44 ` Karel Zak
  13 siblings, 0 replies; 17+ messages in thread
From: Karel Zak @ 2016-08-02 13:44 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jul 17, 2016 at 02:00:02PM +0100, Sami Kerola wrote:
>   git://github.com/kerolasa/lelux-utiliteetit.git oclint

Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-08-02 13:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-17 13:00 [PATCH 00/13] pull: OCLint static code analysis changes Sami Kerola
2016-07-17 13:00 ` [PATCH 01/13] misc: simplify if clauses [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 02/13] switch_root: simplify code and reduce indentation [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 03/13] libfdisk: collapse " Sami Kerola
2016-07-19  8:48   ` Karel Zak
2016-07-21 20:20     ` Sami Kerola
2016-07-17 13:00 ` [PATCH 04/13] lslogins: simplify if clause and move definition and comments [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 05/13] libblkid: simplify if clause [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 06/13] logger: " Sami Kerola
2016-07-17 13:00 ` [PATCH 07/13] syspriv: flip inverted logic [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 08/13] libmount, look: remove dead code [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 09/13] dmesg: drop core at impossible case in read_buffer() [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 10/13] misc: fix declarations shadowing variables in the global scope [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 11/13] setterm: " Sami Kerola
2016-07-17 13:00 ` [PATCH 12/13] agetty: move unreachable code to pre-processor #else segment [oclint] Sami Kerola
2016-07-17 13:00 ` [PATCH 13/13] libblkid: fix debugging macro [oclint] Sami Kerola
2016-08-02 13:44 ` [PATCH 00/13] pull: OCLint static code analysis changes Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.