Hello, I suspect this pull request will not be merged before release 2.21 which is totally fine. While waiting please review, and comment if something seems to be wrong or unnecessary. I suspect couple fixes could fall in previous category. The following changes since commit 0892d88d1a3c155b2791a5137182ab98a22a7bac: tools: use gpg-aggent in ko-release-gen (2012-02-07 11:30:56 +0100) are available in the git repository at: git://github.com/kerolasa/lelux-utiliteetit.git cppcheck for you to fetch changes up to f7df0458b48078f157dadbae370d6ef431a3418c: lib/loopdev: remove loopdev_find_by_backing_file() [cppcheck] (2012-02-07 23:19:55 +0100) ---------------------------------------------------------------- Sami Kerola (19): fsck.cramfs: close open file after usage [cppcheck] mkfs.cramfs: close open file after usage [cppcheck] mkfs.cramfs: check blocksize user input [cppcheck] mkswap: clean up preprocessor branching [cppcheck] raw: remove unnecessary return [cppcheck] fdisk: enhance heads and sectors argument checking [cppcheck] fdisk: remove redundant declaration [cppcheck] sfdisk: free variable which got the allocation [cppcheck] hwclock: clarify operation order [cppcheck] libblkid: clarify operation order [cppcheck] libblkid: allow return value to indicate error [cppcheck] libblkid: verify arroy bound before reference [cppcheck] mount: close file descriptors before exiting [cppcheck] taskset: use appropriate variable type [cppcheck] chcpu: use appropriate variable type [cppcheck] lscpu: clarify calculation precedence [cppcheck] switch_root: close open file after usage [cppcheck] tunelp: free allocation before exit [cppcheck] lib/loopdev: remove loopdev_find_by_backing_file() [cppcheck] disk-utils/fsck.cramfs.c | 2 +- disk-utils/mkfs.cramfs.c | 10 +++++++--- disk-utils/mkswap.c | 4 +++- disk-utils/raw.c | 2 -- fdisk/fdisk.c | 20 +++++++++++++++----- fdisk/fdisk.h | 4 ---- fdisk/sfdisk.c | 6 +++--- hwclock/hwclock.c | 4 ++-- include/loopdev.h | 2 -- lib/loopdev.c | 19 ------------------- libblkid/src/cache.c | 2 +- libblkid/src/probe.c | 2 +- libblkid/src/read.c | 2 +- mount/mount.c | 4 +++- schedutils/taskset.c | 2 +- sys-utils/chcpu.c | 4 ++-- sys-utils/lscpu.c | 4 ++-- sys-utils/switch_root.c | 2 ++ sys-utils/tunelp.c | 2 +- 19 files changed, 45 insertions(+), 52 deletions(-) diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index 0bbe048..d9e145c 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -498,8 +498,8 @@ static void do_file(char *path, struct cramfs_inode *i) } if (i->size) do_uncompress(path, fd, offset, i->size); + close(fd); if (opt_extract) { - close(fd); change_file_status(path, i); } } diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index e7a1de3..c437a56 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -711,6 +711,7 @@ int main(int argc, char **argv) uint32_t crc = crc32(0L, Z_NULL, 0); int c; cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */ + long long tmpblksize; blksize = getpagesize(); total_blocks = 0; @@ -725,9 +726,11 @@ int main(int argc, char **argv) case 'h': usage(MKFS_OK); case 'b': - blksize = strtoll_or_err(optarg, _("failed to parse blocksize argument")); - if (blksize <= 0) - usage(MKFS_USAGE); + tmpblksize = strtoll_or_err(optarg, _("failed to parse blocksize argument")); + if (tmpblksize <= 0 || UINT_MAX < tmpblksize) { + errx(MKFS_USAGE, _("invalid block size")); + } + blksize = tmpblksize; break; case 'E': opt_errors = 1; @@ -875,6 +878,7 @@ int main(int argc, char **argv) (long long) fslen_ub, offset); written = write(fd, rom_image, offset); + close(fd); if (written < 0) err(MKFS_ERROR, _("ROM image")); if (offset != written) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index b963da2..171248b 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -593,8 +593,10 @@ main(int argc, char **argv) { else if (get_linux_version() >= KERNEL_VERSION(2,2,1)) maxpages = V1_MAX_PAGES; else -#endif maxpages = V1_OLD_MAX_PAGES; +#else + maxpages = V1_OLD_MAX_PAGES; +#endif if (PAGES > maxpages) { PAGES = maxpages; diff --git a/disk-utils/raw.c b/disk-utils/raw.c index 84a71ec..c2e0290 100644 --- a/disk-utils/raw.c +++ b/disk-utils/raw.c @@ -168,8 +168,6 @@ int main(int argc, char *argv[]) } return bind(raw_minor, block_major, block_minor); - return 0; - } diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 66c5d18..c0b1c69 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -2956,6 +2956,7 @@ int main(int argc, char **argv) { int j, c; int optl = 0, opts = 0; + long numarg; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -2976,7 +2977,12 @@ main(int argc, char **argv) { user_set_sector_size = 1; break; case 'C': - user_cylinders = atoi(optarg); + numarg = strtol_or_err(optarg, _("cannot parse argument")); + if (numarg < 0 || UINT_MAX < numarg) { + fprintf(stderr, "%s\n", _("number of cylinders out of range, ignoring")); + break; + } + user_cylinders = numarg; break; case 'c': dos_compatible_flag = 0; /* default */ @@ -2990,14 +2996,18 @@ main(int argc, char **argv) { usage(stdout); break; case 'H': - user_heads = atoi(optarg); - if (user_heads <= 0 || user_heads > 256) + numarg = strtol_or_err(optarg, _("cannot parse argument")); + if (numarg < 1 || 256 < numarg) user_heads = 0; + else + user_heads = numarg; break; case 'S': - user_sectors = atoi(optarg); - if (user_sectors <= 0 || user_sectors >= 64) + numarg = strtol_or_err(optarg, _("cannot parse argument")); + if (numarg < 1 || 64 < numarg) user_sectors = 0; + else + user_sectors = numarg; break; case 'l': optl = 1; diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index 9957d76..fed575b 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -111,7 +111,3 @@ extern void bsd_command_prompt(void); extern int check_osf_label(void); extern int btrydev(char * dev); extern void xbsd_print_disklabel(int); - -/* prototypes for fdisksgilabel.c */ -extern int valid_part_table_flag(unsigned char *b); - diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index 6b87b4a..0405816 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -304,7 +304,7 @@ restore_sectors(char *dev) { error(_("partition restore file has wrong size - not restoring\n")); goto err; } - if (!(ss = (char *)malloc(statbuf.st_size))) { + if (!(ss0 = (char *)malloc(statbuf.st_size))) { error(_("out of memory?\n")); goto err; } @@ -315,7 +315,7 @@ restore_sectors(char *dev) { restore_sector_file); goto err; } - if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) { + if (read(fdin, ss0, statbuf.st_size) != statbuf.st_size) { perror("read"); error(_("error reading %s\n"), restore_sector_file); goto err; @@ -328,7 +328,7 @@ restore_sectors(char *dev) { goto err; } - ss0 = ss; + ss = ss0; ct = statbuf.st_size / 516; while (ct--) { sno = chars_to_ulong((unsigned char *)ss); diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c index 4da2dca..c4eb8ae 100644 --- a/hwclock/hwclock.c +++ b/hwclock/hwclock.c @@ -1641,8 +1641,8 @@ int main(int argc, char **argv) argc); } - if (show + set + systohc + hctosys + systz + adjust + getepoch - + setepoch + predict > 1) { + if ((show + set + systohc + hctosys + systz + adjust + getepoch + + setepoch + predict) > 1) { warnx(_("You have specified multiple functions.\n" "You can only perform one function at a time.")); hwclock_exit(EX_USAGE); diff --git a/include/loopdev.h b/include/loopdev.h index 4e68da8..68db551 100644 --- a/include/loopdev.h +++ b/include/loopdev.h @@ -129,8 +129,6 @@ extern int loopdev_is_autoclear(const char *device); extern char *loopdev_get_backing_file(const char *device); extern int loopdev_is_used(const char *device, const char *filename, uint64_t offset, int flags); -extern char *loopdev_find_by_backing_file(const char *filename, - uint64_t offset, int flags); extern int loopcxt_find_unused(struct loopdev_cxt *lc); extern int loopdev_delete(const char *device); extern int loopdev_count_by_backing_file(const char *filename, char **loopdev); diff --git a/lib/loopdev.c b/lib/loopdev.c index f917f18..243cf51 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -1284,25 +1284,6 @@ int loopcxt_find_by_backing_file(struct loopdev_cxt *lc, const char *filename, } /* - * Returns allocated string with device name - */ -char *loopdev_find_by_backing_file(const char *filename, uint64_t offset, int flags) -{ - struct loopdev_cxt lc; - char *res = NULL; - - if (!filename) - return NULL; - - loopcxt_init(&lc, 0); - if (loopcxt_find_by_backing_file(&lc, filename, offset, flags)) - res = loopcxt_strdup_device(&lc); - loopcxt_deinit(&lc); - - return res; -} - -/* * Returns number of loop devices associated with @file, if only one loop * device is associeted with the given @filename and @loopdev is not NULL then * @loopdev returns name of the device. diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c index 2eab2d3..a60495a 100644 --- a/libblkid/src/cache.c +++ b/libblkid/src/cache.c @@ -262,7 +262,7 @@ int main(int argc, char** argv) argv[0], ret); exit(1); } - if ((ret = blkid_probe_all(cache) < 0)) + if ((ret = blkid_probe_all(cache)) < 0) fprintf(stderr, "error probing devices\n"); blkid_put_cache(cache); diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index d7f24b2..024ce88 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1196,7 +1196,7 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name, const char *fmt, va_list ap) { struct blkid_prval *v; - size_t len; + ssize_t len; v = blkid_probe_assign_value(pr, name); if (!v) diff --git a/libblkid/src/read.c b/libblkid/src/read.c index b284ff0..60d13db 100644 --- a/libblkid/src/read.c +++ b/libblkid/src/read.c @@ -425,7 +425,7 @@ void blkid_read_cache(blkid_cache cache) continue; end = strlen(buf) - 1; /* Continue reading next line if it ends with a backslash */ - while (buf[end] == '\\' && end < sizeof(buf) - 2 && + while (end < (sizeof(buf) - 2) && buf[end] == '\\' && fgets(buf + end, sizeof(buf) - end, file)) { end = strlen(buf) - 1; lineno++; diff --git a/mount/mount.c b/mount/mount.c index 57c0f59..8e3d5a1 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -2753,6 +2753,8 @@ main(int argc, char *argv[]) { result = 0; fsprobe_exit(); - + close(0); + close(1); + close(2); exit (result); } diff --git a/schedutils/taskset.c b/schedutils/taskset.c index 085675d..fd8e29a 100644 --- a/schedutils/taskset.c +++ b/schedutils/taskset.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) cpu_set_t *new_set; pid_t pid = 0; int c, all_tasks = 0; - unsigned int ncpus; + int ncpus; size_t new_setsize, nbits; struct taskset ts; diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index 29b7ab8..79f5167 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -47,7 +47,7 @@ #define _PATH_SYS_CPU_DISPATCH _PATH_SYS_CPU "/dispatching" static cpu_set_t *onlinecpus; -static size_t maxcpus; +static int maxcpus; #define is_cpu_online(cpu) (CPU_ISSET_S((cpu), CPU_ALLOC_SIZE(maxcpus), onlinecpus)) #define num_online_cpus() (CPU_COUNT_S(CPU_ALLOC_SIZE(maxcpus), onlinecpus)) @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); maxcpus = get_max_number_of_cpus(); - if ((int) maxcpus <= 0) + if (maxcpus < 1) errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting")); if (path_exist(_PATH_SYS_CPU_ONLINE)) onlinecpus = path_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE); diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 65e1eb6..801bdd3 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -612,9 +612,9 @@ read_topology(struct lscpu_desc *desc, int num) * calculation easy we make sure that nsockets and * nbooks is at least 1. */ - nsockets = desc->ncpus / nthreads / ncores ?: 1; + nsockets = ((desc->ncpus / nthreads) / ncores) ?: 1; /* number of books */ - nbooks = desc->ncpus / nthreads / ncores / nsockets ?: 1; + nbooks = (((desc->ncpus / nthreads) / ncores) / nsockets) ?: 1; /* all threads, see also read_basicinfo() * -- fallback for kernels without diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c index 1c7375d..0da7842 100644 --- a/sys-utils/switch_root.c +++ b/sys-utils/switch_root.c @@ -155,11 +155,13 @@ static int switchroot(const char *newroot) cfd = open("/", O_RDONLY); if (mount(newroot, "/", NULL, MS_MOVE, NULL) < 0) { + close(cfd); warn(_("failed to mount moving %s to /"), newroot); return -1; } if (chroot(".")) { + close(cfd); warn(_("failed to change root")); return -1; } diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c index f59c6dd..b312d14 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -326,7 +326,7 @@ int main(int argc, char **argv) else printf(_("%s using polling\n"), filename); } - + free(filename); close(fd); return EXIT_SUCCESS; -- Sami Kerola http://www.iki.fi/kerolasa/ -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html