diff options
author | Karel Zak | 2019-05-20 12:35:38 +0200 |
---|---|---|
committer | Karel Zak | 2019-05-20 12:35:38 +0200 |
commit | 002931c485dd66c23b63750a7d9d09637e9bc1ef (patch) | |
tree | f4209fc28f52b9aa6159af0afb43b43f07b4326f | |
parent | Merge branch 'lscpu_midr_updates' of https://github.com/jlinton/util-linux (diff) | |
parent | lib/colors: remove redundant if statement (diff) | |
download | kernel-qcow2-util-linux-002931c485dd66c23b63750a7d9d09637e9bc1ef.tar.gz kernel-qcow2-util-linux-002931c485dd66c23b63750a7d9d09637e9bc1ef.tar.xz kernel-qcow2-util-linux-002931c485dd66c23b63750a7d9d09637e9bc1ef.zip |
Merge branch '2019wk19' of https://github.com/kerolasa/util-linux
* '2019wk19' of https://github.com/kerolasa/util-linux:
lib/colors: remove redundant if statement
wipefs: fix variable / function shadowing [cppcheck]
sulogin: fix variable / function shadowing [cppcheck]
lscpu: remove redundant condition check [cppcheck]
libmount: avoid possible null pointer dereference [cppcheck]
lib/mangle: fix possible null pointer dereference [cppcheck]
sfdisk: remove unnecessary size check [cppcheck]
-rw-r--r-- | disk-utils/sfdisk.c | 2 | ||||
-rw-r--r-- | lib/colors.c | 4 | ||||
-rw-r--r-- | lib/mangle.c | 4 | ||||
-rw-r--r-- | libmount/src/monitor.c | 15 | ||||
-rw-r--r-- | login-utils/sulogin.c | 9 | ||||
-rw-r--r-- | misc-utils/wipefs.c | 8 | ||||
-rw-r--r-- | sys-utils/lscpu.c | 20 |
7 files changed, 33 insertions, 29 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 4a9640d0e..83f3cf8f7 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -134,8 +134,6 @@ static int get_user_reply(const char *prompt, char *buf, size_t bufsz) if (!p) return 1; strncpy(buf, p, bufsz - 1); - if (bufsz != 0) - buf[bufsz - 1] = '\0'; free(p); } else #endif diff --git a/lib/colors.c b/lib/colors.c index ecec0ac30..26f3c81f7 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -662,11 +662,9 @@ static int colors_terminal_is_ready(void) if (setupterm(NULL, STDOUT_FILENO, &ret) != 0 || ret != 1) goto none; ncolors = tigetnum("colors"); - if (ncolors <= 2) - goto none; } #endif - if (ncolors != -1) { + if (1 < ncolors) { DBG(CONF, ul_debug("terminal is ready (supports %d colors)", ncolors)); return 1; } diff --git a/lib/mangle.c b/lib/mangle.c index b514cd8d3..87802fbda 100644 --- a/lib/mangle.c +++ b/lib/mangle.c @@ -155,9 +155,9 @@ int main(int argc, char *argv[]) } x = strdup(argv[2]); - unmangle_to_buffer(x, x, strlen(x) + 1); - if (x) { + unmangle_to_buffer(x, x, strlen(x) + 1); + printf("self-unmangled: '%s'\n", x); free(x); } diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index 2383a734a..730c8bdea 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -794,14 +794,17 @@ int mnt_monitor_next_change(struct libmnt_monitor *mn, me = NULL; } - me->changed = 0; + if (me) { + me->changed = 0; - if (filename) - *filename = me->path; - if (type) - *type = me->type; + if (filename) + *filename = me->path; + if (type) + *type = me->type; - DBG(MONITOR, ul_debugobj(mn, " *** success [changed: %s]", me->path)); + DBG(MONITOR, ul_debugobj(mn, " *** success [changed: %s]", me->path)); + } else + return -EINVAL; return 0; /* success */ } diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 549870d22..9091caf14 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -168,16 +168,17 @@ static void tcinit(struct console *con) tio->c_cc[VMIN] = 1; if (ioctl(fd, TIOCGWINSZ, &ws) == 0) { - int set = 0; + int update = 0; + if (ws.ws_row == 0) { ws.ws_row = 24; - set++; + update++; } if (ws.ws_col == 0) { ws.ws_col = 80; - set++; + update++; } - if (set) + if (update) ignore_result( ioctl(fd, TIOCSWINSZ, &ws) ); } diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 78e5ac376..be728279b 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -307,7 +307,7 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, loff_t *offset, size_t *len) { - const char *off, *type, *mag, *p, *usage = NULL; + const char *off, *type, *mag, *p, *use = NULL; struct wipe_desc *wp; int rc, ispt = 0; @@ -328,7 +328,7 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, len); if (rc) return NULL; - usage = N_("partition-table"); + use = N_("partition-table"); ispt = 1; } else return NULL; @@ -357,8 +357,8 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, if (!wp) return NULL; - if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) - wp->usage = xstrdup(usage); + if (use || blkid_probe_lookup_value(pr, "USAGE", &use, NULL) == 0) + wp->usage = xstrdup(use); wp->type = xstrdup(type); wp->on_disk = 1; diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 7f6277f00..f64d81836 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -1778,10 +1778,12 @@ print_cpus_parsable(struct lscpu_desc *desc, int cols[], int ncols, int c; int cpu = real_cpu_num(desc, i); - if (!mod->offline && desc->online && !is_cpu_online(desc, cpu)) - continue; - if (!mod->online && desc->online && is_cpu_online(desc, cpu)) - continue; + if (desc->online) { + if (!mod->offline && !is_cpu_online(desc, cpu)) + continue; + if (!mod->online && is_cpu_online(desc, cpu)) + continue; + } if (desc->present && !is_cpu_present(desc, cpu)) continue; for (c = 0; c < ncols; c++) { @@ -1835,10 +1837,12 @@ print_cpus_readable(struct lscpu_desc *desc, int cols[], int ncols, struct libscols_line *line; int cpu = real_cpu_num(desc, i); - if (!mod->offline && desc->online && !is_cpu_online(desc, cpu)) - continue; - if (!mod->online && desc->online && is_cpu_online(desc, cpu)) - continue; + if (desc->online) { + if (!mod->offline && !is_cpu_online(desc, cpu)) + continue; + if (!mod->online && is_cpu_online(desc, cpu)) + continue; + } if (desc->present && !is_cpu_present(desc, cpu)) continue; |