Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH 0/3] cppcheck warnings fixes
@ 2015-06-19 19:40 Boris Egorov
  2015-06-19 19:40 ` [PATCH 1/3] sys-utils/disk-utils/lib: fix printf format types [cppcheck] Boris Egorov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Boris Egorov @ 2015-06-19 19:40 UTC (permalink / raw)
  To: util-linux; +Cc: Boris Egorov

Following patches fix some cppcheck (version 1.70 dev) warnings.

Boris Egorov (3):
  sys-utils/disk-utils/lib: fix printf format types [cppcheck]
  libblkid/whereis: simplify some conditions [cppcheck]
  cfdisk: fix condition logic [cppcheck]

 disk-utils/cfdisk.c      |  2 +-
 disk-utils/fsck.cramfs.c |  6 +++---
 disk-utils/mkfs.bfs.c    |  6 +++---
 lib/cpuset.c             |  6 +++---
 libblkid/src/tag.c       |  2 +-
 misc-utils/whereis.c     |  2 +-
 sys-utils/chcpu.c        | 38 +++++++++++++++++++-------------------
 sys-utils/hwclock-rtc.c  |  2 +-
 sys-utils/ipcs.c         |  4 ++--
 sys-utils/readprofile.c  | 12 ++++++------
 10 files changed, 40 insertions(+), 40 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in

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

* [PATCH 1/3] sys-utils/disk-utils/lib: fix printf format types [cppcheck]
  2015-06-19 19:40 [PATCH 0/3] cppcheck warnings fixes Boris Egorov
@ 2015-06-19 19:40 ` Boris Egorov
  2015-06-19 19:41 ` [PATCH 2/3] libblkid/whereis: simplify some conditions [cppcheck] Boris Egorov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Boris Egorov @ 2015-06-19 19:40 UTC (permalink / raw)
  To: util-linux; +Cc: Boris Egorov

Fix 'invalidPrintfArgType' cppcheck warnings

Signed-off-by: Boris Egorov <egorov@linux.com>
---
 disk-utils/fsck.cramfs.c |  6 +++---
 disk-utils/mkfs.bfs.c    |  6 +++---
 lib/cpuset.c             |  6 +++---
 sys-utils/chcpu.c        | 38 +++++++++++++++++++-------------------
 sys-utils/hwclock-rtc.c  |  2 +-
 sys-utils/ipcs.c         |  4 ++--
 sys-utils/readprofile.c  | 12 ++++++------
 7 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index 0a375f1..d5d3790 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -382,14 +382,14 @@ static void do_uncompress(char *path, int outfd, unsigned long offset,
 		offset += 4;
 		if (curr == next) {
 			if (opt_verbose > 1)
-				printf(_("  hole at %ld (%zd)\n"), curr,
+				printf(_("  hole at %lu (%zu)\n"), curr,
 				       blksize);
 			if (size < blksize)
 				out = size;
 			memset(outbuffer, 0x00, out);
 		} else {
 			if (opt_verbose > 1)
-				printf(_("  uncompressing block at %ld to %ld (%ld)\n"),
+				printf(_("  uncompressing block at %lu to %lu (%lu)\n"),
 				       curr, next, next - curr);
 			out = uncompress_block(romfs_read(curr), next - curr);
 		}
@@ -544,7 +544,7 @@ static void do_symlink(char *path, struct cramfs_inode *i)
 		xasprintf(&str, "%s -> %s", path, outbuffer);
 		print_node('l', i, str);
 		if (opt_verbose > 1)
-			printf(_("  uncompressing block at %ld to %ld (%ld)\n"),
+			printf(_("  uncompressing block at %lu to %lu (%lu)\n"),
 			       curr, next, next - curr);
 		free(str);
 	}
diff --git a/disk-utils/mkfs.bfs.c b/disk-utils/mkfs.bfs.c
index 2a22364..7057194 100644
--- a/disk-utils/mkfs.bfs.c
+++ b/disk-utils/mkfs.bfs.c
@@ -246,12 +246,12 @@ int main(int argc, char **argv)
 		fprintf(stderr, _("FSname: <%-6s>\n"), fsname);
 		fprintf(stderr, _("BlockSize: %d\n"), BFS_BLOCKSIZE);
 		if (ino_blocks == 1)
-			fprintf(stderr, _("Inodes: %lu (in 1 block)\n"),
+			fprintf(stderr, _("Inodes: %ld (in 1 block)\n"),
 				inodes);
 		else
-			fprintf(stderr, _("Inodes: %lu (in %llu blocks)\n"),
+			fprintf(stderr, _("Inodes: %ld (in %llu blocks)\n"),
 				inodes, ino_blocks);
-		fprintf(stderr, _("Blocks: %lld\n"), total_blocks);
+		fprintf(stderr, _("Blocks: %llu\n"), total_blocks);
 		fprintf(stderr, _("Inode end: %d, Data end: %d\n"),
 			le32_to_cpu(sb.s_start) - 1, le32_to_cpu(sb.s_end));
 	}
diff --git a/lib/cpuset.c b/lib/cpuset.c
index d715720..41c0eed 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -169,12 +169,12 @@ char *cpulist_create(char *str, size_t len,
 					break;
 			}
 			if (!run)
-				rlen = snprintf(ptr, len, "%zd,", i);
+				rlen = snprintf(ptr, len, "%zu,", i);
 			else if (run == 1) {
-				rlen = snprintf(ptr, len, "%zd,%zd,", i, i + 1);
+				rlen = snprintf(ptr, len, "%zu,%zu,", i, i + 1);
 				i++;
 			} else {
-				rlen = snprintf(ptr, len, "%zd-%zd,", i, i + run);
+				rlen = snprintf(ptr, len, "%zu-%zu,", i, i + run);
 				i += run;
 			}
 			if (rlen < 0 || (size_t) rlen + 1 > len)
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index 428fdc2..50b834c 100644
--- a/sys-utils/chcpu.c
+++ b/sys-utils/chcpu.c
@@ -84,22 +84,22 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
 		if (!CPU_ISSET(cpu, cpu_set))
 			continue;
 		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
-			warnx(_("CPU %d does not exist"), cpu);
+			warnx(_("CPU %u does not exist"), cpu);
 			fails++;
 			continue;
 		}
 		if (!path_exist(_PATH_SYS_CPU "/cpu%d/online", cpu)) {
-			warnx(_("CPU %d is not hot pluggable"), cpu);
+			warnx(_("CPU %u is not hot pluggable"), cpu);
 			fails++;
 			continue;
 		}
 		online = path_read_s32(_PATH_SYS_CPU "/cpu%d/online", cpu);
 		if ((online == 1) && (enable == 1)) {
-			printf(_("CPU %d is already enabled\n"), cpu);
+			printf(_("CPU %u is already enabled\n"), cpu);
 			continue;
 		}
 		if ((online == 0) && (enable == 0)) {
-			printf(_("CPU %d is already disabled\n"), cpu);
+			printf(_("CPU %u is already disabled\n"), cpu);
 			continue;
 		}
 		if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu))
@@ -107,25 +107,25 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
 		if (enable) {
 			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
 			if ((rc == -1) && (configured == 0)) {
-				warn(_("CPU %d enable failed (CPU is deconfigured)"), cpu);
+				warn(_("CPU %u enable failed (CPU is deconfigured)"), cpu);
 				fails++;
 			} else if (rc == -1) {
-				warn(_("CPU %d enable failed"), cpu);
+				warn(_("CPU %u enable failed"), cpu);
 				fails++;
 			} else
-				printf(_("CPU %d enabled\n"), cpu);
+				printf(_("CPU %u enabled\n"), cpu);
 		} else {
 			if (onlinecpus && num_online_cpus() == 1) {
-				warnx(_("CPU %d disable failed (last enabled CPU)"), cpu);
+				warnx(_("CPU %u disable failed (last enabled CPU)"), cpu);
 				fails++;
 				continue;
 			}
 			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
 			if (rc == -1) {
-				warn(_("CPU %d disable failed"), cpu);
+				warn(_("CPU %u disable failed"), cpu);
 				fails++;
 			} else {
-				printf(_("CPU %d disabled\n"), cpu);
+				printf(_("CPU %u disabled\n"), cpu);
 				if (onlinecpus)
 					CPU_CLR(cpu, onlinecpus);
 			}
@@ -176,44 +176,44 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
 		if (!CPU_ISSET(cpu, cpu_set))
 			continue;
 		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
-			warnx(_("CPU %d does not exist"), cpu);
+			warnx(_("CPU %u does not exist"), cpu);
 			fails++;
 			continue;
 		}
 		if (!path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu)) {
-			warnx(_("CPU %d is not configurable"), cpu);
+			warnx(_("CPU %u is not configurable"), cpu);
 			fails++;
 			continue;
 		}
 		current = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
 		if ((current == 1) && (configure == 1)) {
-			printf(_("CPU %d is already configured\n"), cpu);
+			printf(_("CPU %u is already configured\n"), cpu);
 			continue;
 		}
 		if ((current == 0) && (configure == 0)) {
-			printf(_("CPU %d is already deconfigured\n"), cpu);
+			printf(_("CPU %u is already deconfigured\n"), cpu);
 			continue;
 		}
 		if ((current == 1) && (configure == 0) && onlinecpus &&
 		    is_cpu_online(cpu)) {
-			warnx(_("CPU %d deconfigure failed (CPU is enabled)"), cpu);
+			warnx(_("CPU %u deconfigure failed (CPU is enabled)"), cpu);
 			fails++;
 			continue;
 		}
 		if (configure) {
 			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
 			if (rc == -1) {
-				warn(_("CPU %d configure failed"), cpu);
+				warn(_("CPU %u configure failed"), cpu);
 				fails++;
 			} else
-				printf(_("CPU %d configured\n"), cpu);
+				printf(_("CPU %u configured\n"), cpu);
 		} else {
 			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
 			if (rc == -1) {
-				warn(_("CPU %d deconfigure failed"), cpu);
+				warn(_("CPU %u deconfigure failed"), cpu);
 				fails++;
 			} else
-				printf(_("CPU %d deconfigured\n"), cpu);
+				printf(_("CPU %u deconfigured\n"), cpu);
 		}
 	}
 
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c
index 91721f3..812b65b 100644
--- a/sys-utils/hwclock-rtc.c
+++ b/sys-utils/hwclock-rtc.c
@@ -471,7 +471,7 @@ int set_epoch_rtc(unsigned long epoch)
 	}
 
 	if (debug)
-		printf(_("setting epoch to %ld "
+		printf(_("setting epoch to %lu "
 			 "with RTC_EPOCH_SET ioctl to %s.\n"), epoch,
 		       rtc_dev_name);
 
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 74d8766..eaab922 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -359,7 +359,7 @@ static void do_sem (char format)
 		printf (_("max semaphores per array = %d\n"), lim.semmsl);
 		printf (_("max semaphores system wide = %d\n"), lim.semmns);
 		printf (_("max ops per semop call = %d\n"), lim.semopm);
-		printf (_("semaphore max value = %d\n"), lim.semvmx);
+		printf (_("semaphore max value = %u\n"), lim.semvmx);
 		return;
 	}
 	case STATUS:
@@ -649,7 +649,7 @@ static void print_sem(int semid)
 
 	for (i = 0; i < semdata->sem_nsems; i++) {
 		struct sem_elem *e = &semdata->elements[i];
-		printf("%-10zd %-10d %-10d %-10d %-10d\n",
+		printf("%-10zu %-10d %-10d %-10d %-10d\n",
 		       i, e->semval, e->ncount, e->zcount, e->pid);
 	}
 	printf("\n");
diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c
index eb6b8ec..3ba866e 100644
--- a/sys-utils/readprofile.c
+++ b/sys-utils/readprofile.c
@@ -283,7 +283,7 @@ int main(int argc, char **argv)
 
 	step = buf[0];
 	if (optInfo) {
-		printf(_("Sampling_step: %i\n"), step);
+		printf(_("Sampling_step: %u\n"), step);
 		exit(EXIT_SUCCESS);
 	}
 
@@ -364,10 +364,10 @@ int main(int argc, char **argv)
 		} else if ((this || optAll) &&
 			   (fn_len = next_add - fn_add) != 0) {
 			if (optVerbose)
-				printf("%016llx %-40s %6i %8.4f\n", fn_add,
+				printf("%016llx %-40s %6u %8.4f\n", fn_add,
 				       fn_name, this, this / (double)fn_len);
 			else
-				printf("%6i %-40s %8.4f\n",
+				printf("%6u %-40s %8.4f\n",
 				       this, fn_name, this / (double)fn_len);
 			if (optSub) {
 				unsigned long long scan;
@@ -393,14 +393,14 @@ int main(int argc, char **argv)
 	}
 
 	/* clock ticks, out of kernel text - probably modules */
-	printf("%6i %s\n", buf[len / sizeof(*buf) - 1], "*unknown*");
+	printf("%6u %s\n", buf[len / sizeof(*buf) - 1], "*unknown*");
 
 	/* trailer */
 	if (optVerbose)
-		printf("%016x %-40s %6i %8.4f\n",
+		printf("%016x %-40s %6u %8.4f\n",
 		       0, "total", total, total / (double)(fn_add - add0));
 	else
-		printf("%6i %-40s %8.4f\n",
+		printf("%6u %-40s %8.4f\n",
 		       total, _("total"), total / (double)(fn_add - add0));
 
 	popenMap ? pclose(map) : fclose(map);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in

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

* [PATCH 2/3] libblkid/whereis: simplify some conditions [cppcheck]
  2015-06-19 19:40 [PATCH 0/3] cppcheck warnings fixes Boris Egorov
  2015-06-19 19:40 ` [PATCH 1/3] sys-utils/disk-utils/lib: fix printf format types [cppcheck] Boris Egorov
@ 2015-06-19 19:41 ` Boris Egorov
  2015-06-19 19:41 ` [PATCH 3/3] cfdisk: fix condition logic [cppcheck] Boris Egorov
  2015-06-25 10:10 ` [PATCH 0/3] cppcheck warnings fixes Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Boris Egorov @ 2015-06-19 19:41 UTC (permalink / raw)
  To: util-linux; +Cc: Boris Egorov

[misc-utils/whereis.c:466]: (style) Redundant condition: uflag.
'A && (!A || B)' is equivalent to 'A || B'
[libblkid/src/tag.c:373]: (style) Redundant condition: dev.
'A && (!A || B)' is equivalent to 'A || B'

Signed-off-by: Boris Egorov <egorov@linux.com>
---
 libblkid/src/tag.c   | 2 +-
 misc-utils/whereis.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libblkid/src/tag.c b/libblkid/src/tag.c
index 6af8062..281612a 100644
--- a/libblkid/src/tag.c
+++ b/libblkid/src/tag.c
@@ -370,7 +370,7 @@ try_again:
 	}
 	if (dev && !(dev->bid_flags & BLKID_BID_FL_VERIFIED)) {
 		dev = blkid_verify(cache, dev);
-		if (!dev || (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED)))
+		if (!dev || dev->bid_flags & BLKID_BID_FL_VERIFIED)
 			goto try_again;
 	}
 
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 96a930e..697d666 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -463,7 +463,7 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
 
 	free(wait);
 
-	if (!uflag || (uflag && count > 1))
+	if (!uflag || count > 1)
 		putchar('\n');
 	return;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in

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

* [PATCH 3/3] cfdisk: fix condition logic [cppcheck]
  2015-06-19 19:40 [PATCH 0/3] cppcheck warnings fixes Boris Egorov
  2015-06-19 19:40 ` [PATCH 1/3] sys-utils/disk-utils/lib: fix printf format types [cppcheck] Boris Egorov
  2015-06-19 19:41 ` [PATCH 2/3] libblkid/whereis: simplify some conditions [cppcheck] Boris Egorov
@ 2015-06-19 19:41 ` Boris Egorov
  2015-06-25 10:10 ` [PATCH 0/3] cppcheck warnings fixes Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Boris Egorov @ 2015-06-19 19:41 UTC (permalink / raw)
  To: util-linux; +Cc: Boris Egorov

[disk-utils/cfdisk.c:1181] -> [disk-utils/cfdisk.c:1181]: (warning)
Possible null pointer dereference: data - otherwise it is redundant to
check it against null.

Signed-off-by: Boris Egorov <egorov@linux.com>
---
 disk-utils/cfdisk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 6f26a3d..4627107 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1178,7 +1178,7 @@ inline static int extra_insert_pair(struct cfdisk_line *l, const char *name, con
 
 	assert(l);
 
-	if (!data && !*data)
+	if (!data || !*data)
 		return 0;
 
 	lsl = scols_table_new_line(l->extra, NULL);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in

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

* Re: [PATCH 0/3] cppcheck warnings fixes
  2015-06-19 19:40 [PATCH 0/3] cppcheck warnings fixes Boris Egorov
                   ` (2 preceding siblings ...)
  2015-06-19 19:41 ` [PATCH 3/3] cfdisk: fix condition logic [cppcheck] Boris Egorov
@ 2015-06-25 10:10 ` Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2015-06-25 10:10 UTC (permalink / raw)
  To: Boris Egorov; +Cc: util-linux

On Sat, Jun 20, 2015 at 01:40:58AM +0600, Boris Egorov wrote:
>  disk-utils/cfdisk.c      |  2 +-
>  disk-utils/fsck.cramfs.c |  6 +++---
>  disk-utils/mkfs.bfs.c    |  6 +++---
>  lib/cpuset.c             |  6 +++---
>  libblkid/src/tag.c       |  2 +-
>  misc-utils/whereis.c     |  2 +-
>  sys-utils/chcpu.c        | 38 +++++++++++++++++++-------------------
>  sys-utils/hwclock-rtc.c  |  2 +-
>  sys-utils/ipcs.c         |  4 ++--
>  sys-utils/readprofile.c  | 12 ++++++------
>  10 files changed, 40 insertions(+), 40 deletions(-)

Applied, thanks!

    Karel

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

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

end of thread, other threads:[~2015-06-25 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-19 19:40 [PATCH 0/3] cppcheck warnings fixes Boris Egorov
2015-06-19 19:40 ` [PATCH 1/3] sys-utils/disk-utils/lib: fix printf format types [cppcheck] Boris Egorov
2015-06-19 19:41 ` [PATCH 2/3] libblkid/whereis: simplify some conditions [cppcheck] Boris Egorov
2015-06-19 19:41 ` [PATCH 3/3] cfdisk: fix condition logic [cppcheck] Boris Egorov
2015-06-25 10:10 ` [PATCH 0/3] cppcheck warnings fixes Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox