* [PATCH 00/11] pull: various small changes
@ 2017-06-08 19:52 Sami Kerola
2017-06-08 19:52 ` [PATCH 01/11] misc: fallthrough fixes Sami Kerola
` (11 more replies)
0 siblings, 12 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Hello,
Here's few changes that I have been holding back while the project was
having release freeze. Most of the changes are related to various warnings
noticed before release, but that I did not think are important enough to be
sent while seeking for stability. Functional improvements include rename(1)
shortcut to exit, and uuidgen(1) date parsing option. Even if everything
else is rejected I really hope these two are accepted.
----------------------------------------------------------------
The following changes since commit f8416301c195d50a21cb54d9ea9abeccc40f9ee7:
libmount: use mount table filter on --no-canonicalize (2017-06-07 11:35:26 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git 2017wk23
for you to fetch changes up to 53949f09430181beee4fb9f546d9a31313f4fd68:
lib: remove _RLD_ from forbid environment variable list (2017-06-08 20:42:20 +0100)
----------------------------------------------------------------
Sami Kerola (11):
misc: fallthrough fixes
line: do not print new line if nothing else was printed
rename: notice when expression and replacement are the same string
uuidgen: slice up the usage text
uuidgen: add --date option to display time when uuid was generated
isosize: avoid reading more data than what is needed
misc: fix reassigned values before old ones has been used [cppcheck]
losetup: add missing initializer [clang]
misc: remove stray semicolons
lib: simplify cpuset if clauses that return
lib: remove _RLD_ from forbid environment variable list
bash-completion/uuidgen | 5 ++-
disk-utils/cfdisk.c | 10 +++---
disk-utils/fdisk-menu.c | 2 +-
disk-utils/isosize.c | 57 ++++++---------------------------
disk-utils/mkfs.cramfs.c | 2 +-
disk-utils/mkfs.minix.c | 2 +-
disk-utils/sfdisk.c | 6 ++--
include/c.h | 18 +++++++++++
lib/cpuset.c | 12 +++----
lib/env.c | 1 -
lib/mbsalign.c | 2 +-
libblkid/src/devno.c | 2 +-
libblkid/src/probe.c | 2 +-
libblkid/src/superblocks/adaptec_raid.c | 2 +-
libblkid/src/topology/md.c | 4 +--
libfdisk/src/gpt.c | 2 +-
libfdisk/src/script.c | 2 +-
libmount/src/btrfs.c | 6 ++--
libmount/src/cache.c | 6 ++--
libmount/src/context.c | 2 +-
libmount/src/context_mount.c | 2 +-
libmount/src/context_umount.c | 4 +--
libmount/src/optstr.c | 2 +-
libmount/src/tab_diff.c | 4 +--
libmount/src/tab_update.c | 2 +-
libsmartcols/src/column.c | 4 +--
libsmartcols/src/table_print.c | 2 +-
login-utils/last.c | 2 +-
login-utils/lslogins.c | 4 +--
login-utils/su-common.c | 1 +
login-utils/sulogin.c | 7 ++--
misc-utils/Makemodule.am | 2 +-
misc-utils/cal.c | 8 ++---
misc-utils/findmnt-verify.c | 2 +-
misc-utils/findmnt.c | 10 +++---
misc-utils/lsblk.c | 2 +-
misc-utils/rename.c | 6 ++--
misc-utils/test_uuidd.c | 2 +-
misc-utils/uuidgen.1 | 8 +++++
misc-utils/uuidgen.c | 47 ++++++++++++++++++++++++---
sys-utils/flock.c | 2 +-
sys-utils/hwclock.c | 3 +-
sys-utils/ipcrm.c | 3 ++
sys-utils/losetup.c | 4 +--
sys-utils/lsipc.c | 2 +-
sys-utils/nsenter.c | 2 +-
sys-utils/setarch.c | 2 +-
sys-utils/swapon.c | 2 +-
sys-utils/unshare.c | 4 +--
term-utils/agetty.c | 4 +--
term-utils/script.c | 4 +--
term-utils/wall.c | 2 +-
tests/expected/uuid/uuidgen | 6 ++++
tests/ts/uuid/uuidgen | 10 ++++++
text-utils/column.c | 2 +-
text-utils/hexdump-parse.c | 2 +-
text-utils/line.c | 6 ++--
text-utils/more.c | 5 +--
text-utils/pg.c | 4 +--
text-utils/ul.c | 4 +--
60 files changed, 195 insertions(+), 144 deletions(-)
--
2.13.1
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 01/11] misc: fallthrough fixes
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-09 11:14 ` Ruediger Meier
2017-06-08 19:52 ` [PATCH 02/11] line: do not print new line if nothing else was printed Sami Kerola
` (10 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/cfdisk.c | 8 ++++----
| 2 +-
disk-utils/mkfs.cramfs.c | 2 +-
disk-utils/mkfs.minix.c | 2 +-
disk-utils/sfdisk.c | 6 +++---
include/c.h | 18 ++++++++++++++++++
libblkid/src/topology/md.c | 4 ++--
libsmartcols/src/table_print.c | 2 +-
login-utils/last.c | 2 +-
login-utils/lslogins.c | 4 ++--
login-utils/su-common.c | 1 +
login-utils/sulogin.c | 7 +++----
misc-utils/cal.c | 8 ++++----
misc-utils/findmnt.c | 2 +-
misc-utils/lsblk.c | 2 +-
misc-utils/rename.c | 3 +--
sys-utils/flock.c | 2 +-
sys-utils/hwclock.c | 3 ++-
sys-utils/ipcrm.c | 3 +++
sys-utils/lsipc.c | 2 +-
sys-utils/nsenter.c | 2 +-
sys-utils/setarch.c | 2 +-
sys-utils/unshare.c | 2 +-
term-utils/agetty.c | 4 ++--
term-utils/script.c | 4 ++--
text-utils/hexdump-parse.c | 2 +-
text-utils/more.c | 5 +++--
text-utils/pg.c | 4 ++--
text-utils/ul.c | 4 ++--
29 files changed, 67 insertions(+), 45 deletions(-)
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 37f998bab..1b2bc11fb 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1496,7 +1496,7 @@ static int ui_menu_move(struct cfdisk *cf, int key)
ui_menu_goto(cf, (int) m->idx - m->page_sz);
return 0;
}
- /* fallthrough */
+ UL_FALLTHROUGH;
case KEY_HOME:
ui_menu_goto(cf, 0);
return 0;
@@ -1505,7 +1505,7 @@ static int ui_menu_move(struct cfdisk *cf, int key)
ui_menu_goto(cf, m->idx + m->page_sz);
return 0;
}
- /* fallthrough */
+ UL_FALLTHROUGH;
case KEY_END:
ui_menu_goto(cf, m->nitems);
return 0;
@@ -2503,7 +2503,7 @@ static int ui_run(struct cfdisk *cf)
ui_table_goto(cf, (int) cf->lines_idx - cf->page_sz);
break;
}
- /* fallthrough */
+ UL_FALLTHROUGH;
case KEY_HOME:
ui_table_goto(cf, 0);
break;
@@ -2512,7 +2512,7 @@ static int ui_run(struct cfdisk *cf)
ui_table_goto(cf, cf->lines_idx + cf->page_sz);
break;
}
- /* fallthrough */
+ UL_FALLTHROUGH;
case KEY_END:
ui_table_goto(cf, (int) cf->nlines - 1);
break;
--git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c
index 9ab28c43f..e42ebcd56 100644
--- a/disk-utils/fdisk-menu.c
+++ b/disk-utils/fdisk-menu.c
@@ -579,7 +579,7 @@ static int generic_menu_cb(struct fdisk_context **cxt0,
rc = fdisk_reread_partition_table(cxt);
if (!rc)
rc = fdisk_deassign_device(cxt, 0);
- /* fallthrough */
+ UL_FALLTHROUGH;
case 'q':
fdisk_unref_context(cxt);
fputc('\n', stdout);
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index f277aaf23..77b4467e7 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -123,7 +123,7 @@ struct entry {
#define CRAMFS_OFFSET_WIDTH 26
/* Input status of 0 to print help and exit without an error. */
-static void
+static void __attribute__((__noreturn__))
usage(int status) {
FILE *stream = status ? stderr : stdout;
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index 47a155c55..fa7dc3270 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -765,7 +765,7 @@ int main(int argc, char ** argv)
break;
case 'v': /* kept for backwards compatibility */
warnx(_("-v is ambiguous, use '-2' instead"));
- /* fallthrough */
+ UL_FALLTHROUGH;
case '2':
fs_version = 2;
break;
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 2ac8cef02..f0b391de3 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1825,7 +1825,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
break;
}
}
- /* fallthrough */
+ UL_FALLTHROUGH;
case SFDISK_DONE_WRITE:
rc = write_changes(sf);
break;
@@ -2025,7 +2025,7 @@ int main(int argc, char *argv[])
break;
case 'J':
sf->json = 1;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 'd':
sf->act = ACT_DUMP;
break;
@@ -2037,7 +2037,7 @@ int main(int argc, char *argv[])
break;
case 'G':
warnx(_("--show-pt-geometry is no more implemented. Using --show-geometry."));
- /* fallthrough */
+ UL_FALLTHROUGH;
case 'g':
sf->act = ACT_SHOW_GEOM;
break;
diff --git a/include/c.h b/include/c.h
index a5162b964..8a67b5dfb 100644
--- a/include/c.h
+++ b/include/c.h
@@ -77,6 +77,24 @@
#endif
/*
+ * Statement Attributes
+ */
+#if defined(__clang__)
+# ifndef __has_cpp_attribute
+# define __has_cpp_attribute(x) 0
+# endif
+# if __has_cpp_attribute(clang::fallthrough)
+# define UL_FALLTHROUGH [[clang::fallthrough]]
+# else
+# define UL_FALLTHROUGH /* fall through */
+# endif
+#elif defined(__GNUC__) || defined(__GNUG__)
+# define UL_FALLTHROUGH __attribute__((fallthrough))
+#else
+# define UL_FALLTHROUGH /* FALLTHRU */
+#endif
+
+/*
* Force a compilation error if condition is true, but also produce a
* result (of value 0 and type size_t), so the expression can be used
* e.g. in a structure initializer (or wherever else comma expressions
diff --git a/libblkid/src/topology/md.c b/libblkid/src/topology/md.c
index 5eba94787..7081d8993 100644
--- a/libblkid/src/topology/md.c
+++ b/libblkid/src/topology/md.c
@@ -121,11 +121,11 @@ static int probe_md_tp(blkid_probe pr,
switch (md.level) {
case 6:
md.raid_disks--;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 5:
case 4:
md.raid_disks--;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 1:
case 0:
case 10:
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 8cd737c8b..691a4b2f8 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -1412,7 +1412,7 @@ static int initialize_printing(struct libscols_table *tb, struct libscols_buffer
case SCOLS_FMT_JSON:
if (tb->format == SCOLS_FMT_JSON)
extra_bufsz += tb->nlines * 3; /* indention */
- /* fallthrough */
+ UL_FALLTHROUGH;
case SCOLS_FMT_EXPORT:
{
struct libscols_column *cl;
diff --git a/login-utils/last.c b/login-utils/last.c
index f93ec7fbf..ad23c986a 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -830,7 +830,7 @@ static void process_wtmp_file(const struct last_control *ctl,
c = whydown;
quit = list(ctl, &ut, lastboot, c);
}
- /* FALLTHRU */
+ UL_FALLTHROUGH;
case DEAD_PROCESS:
/*
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index ab04c10bb..ec3a966cd 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -926,13 +926,13 @@ static struct libscols_table *setup_table(struct lslogins_control *ctl)
break;
case OUT_NEWLINE:
scols_table_set_column_separator(table, "\n");
- /* fallthrough */
+ UL_FALLTHROUGH;
case OUT_EXPORT:
scols_table_enable_export(table, 1);
break;
case OUT_NUL:
scols_table_set_line_separator(table, "\0");
- /* fallthrough */
+ UL_FALLTHROUGH;
case OUT_RAW:
scols_table_enable_raw(table, 1);
break;
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 0999795c8..9fae8f105 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -899,6 +899,7 @@ su_main (int argc, char **argv, int mode)
/* fallthrough if -u <user> is not specified, then follow
* traditional su(1) behavior
*/
+ UL_FALLTHROUGH;
case SU_MODE:
if (optind < argc)
new_user = argv[optind++];
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index 2487838e7..36468ef0b 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -267,11 +267,11 @@ static void tcfinal(struct console *con)
break;
case 1: /* odd parity */
tio->c_cflag |= PARODD;
- /* fall through */
+ UL_FALLTHROUGH;
case 2: /* even parity */
tio->c_cflag |= PARENB;
tio->c_iflag |= (INPCK | ISTRIP);
- /* fall through */
+ UL_FALLTHROUGH;
case (1 | 2): /* no parity bit */
tio->c_cflag &= ~CSIZE;
tio->c_cflag |= CS7;
@@ -971,7 +971,6 @@ int main(int argc, char **argv)
switch ((con->pid = fork())) {
case 0:
mask_signal(SIGCHLD, SIG_DFL, NULL);
- /* fall through */
nofork:
setup(con);
while (1) {
@@ -1024,7 +1023,7 @@ int main(int argc, char **argv)
exit(0);
case -1:
warn(_("fork failed"));
- /* fall through */
+ UL_FALLTHROUGH;
default:
break;
}
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 604eb26a7..d20ec7f89 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -431,7 +431,7 @@ int main(int argc, char **argv)
ctl.req.day = strtos32_or_err(*argv++, _("illegal day value"));
if (ctl.req.day < 1 || DAYS_IN_MONTH < ctl.req.day)
errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), DAYS_IN_MONTH);
- /* FALLTHROUGH */
+ UL_FALLTHROUGH;
case 2:
if (isdigit(**argv))
ctl.req.month = strtos32_or_err(*argv++, _("illegal month value: use 1-12"));
@@ -443,7 +443,7 @@ int main(int argc, char **argv)
}
if (ctl.req.month < 1 || MONTHS_IN_YEAR < ctl.req.month)
errx(EXIT_FAILURE, _("illegal month value: use 1-12"));
- /* FALLTHROUGH */
+ UL_FALLTHROUGH;
case 1:
ctl.req.year = strtos32_or_err(*argv++, _("illegal year value"));
if (ctl.req.year < SMALLEST_YEAR)
@@ -802,10 +802,10 @@ static void monthly(const struct cal_control *ctl)
switch (ctl->num_months % ctl->months_in_row){
case 1:
m1.next = NULL;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 2:
m2.next = NULL;
- /* fallthrough */
+ UL_FALLTHROUGH;
}
}
for (m = &m1; m; m = m->next){
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 86b6b9aa1..5b8d345b1 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -1458,7 +1458,7 @@ int main(int argc, char *argv[])
break;
case 'M':
flags |= FL_STRICTTARGET;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 'T':
set_match(COL_TARGET, optarg);
flags |= FL_NOSWAPMATCH;
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 79077af07..7a3038cc9 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1847,7 +1847,7 @@ int main(int argc, char *argv[])
lsblk->sort_id = column_name_to_id(optarg, strlen(optarg));
if (lsblk->sort_id >= 0)
break;
- /* fallthrough */
+ UL_FALLTHROUGH;
default:
errtryhelp(EXIT_FAILURE);
}
diff --git a/misc-utils/rename.c b/misc-utils/rename.c
index 65ac543ef..a7671fa11 100644
--- a/misc-utils/rename.c
+++ b/misc-utils/rename.c
@@ -174,7 +174,7 @@ int main(int argc, char **argv)
switch (c) {
case 'n':
noact = 1;
- /* fallthrough */
+ UL_FALLTHROUGH;
case 'o':
nooverwrite = 1;
break;
@@ -189,7 +189,6 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
case 'h':
usage(stdout);
- /* fallthrough */
default:
errtryhelp(EXIT_FAILURE);
}
diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index 8af1e8ade..3fd2d8ad7 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -305,7 +305,7 @@ int main(int argc, char *argv[])
if (open_flags & O_RDWR)
break;
}
- /* go through */
+ UL_FALLTHROUGH;
default:
/* Other errors */
if (filename)
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 603146079..c76f25d2e 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -1209,7 +1209,8 @@ static void out_version(void)
* fmt, ... ), show a usage information and terminate the program
* afterwards.
*/
-static void usage(const struct hwclock_control *ctl, const char *fmt, ...)
+static void __attribute__((__noreturn__))
+usage(const struct hwclock_control *ctl, const char *fmt, ...)
{
FILE *usageto;
va_list ap;
diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index 0432b224f..f24e2f1ee 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -346,6 +346,7 @@ int main(int argc, char **argv)
ret++;
break;
}
+ UL_FALLTHROUGH;
case 'm':
if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument"));
@@ -359,6 +360,7 @@ int main(int argc, char **argv)
ret++;
break;
}
+ UL_FALLTHROUGH;
case 'q':
if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument"));
@@ -372,6 +374,7 @@ int main(int argc, char **argv)
ret++;
break;
}
+ UL_FALLTHROUGH;
case 's':
if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument"));
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 3e7586b32..6ec192ef6 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -343,7 +343,7 @@ static struct libscols_table *new_table(struct lsipc_control *ctl)
switch(ctl->outmode) {
case OUT_NEWLINE:
scols_table_set_column_separator(table, "\n");
- /* fallthrough */
+ UL_FALLTHROUGH;
case OUT_EXPORT:
scols_table_enable_export(table, 1);
break;
diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index afa1b9c50..6ad0b0fe0 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -65,7 +65,7 @@ static struct namespace_file {
{ .nstype = 0, .name = NULL, .fd = -1 }
};
-static void usage(int status)
+static void __attribute__((__noreturn__)) usage(int status)
{
FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index eb9cf21a0..94d9413d8 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -377,7 +377,7 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
} else
warnx(_("unrecognized option '--list'"));
- /* fallthrough */
+ UL_FALLTHROUGH;
default:
errtryhelp(EXIT_FAILURE);
}
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index bccd75f3a..6c5c2e2f9 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -238,7 +238,7 @@ static void bind_ns_files_from_child(pid_t *child, int fds[2])
}
}
-static void usage(int status)
+static void __attribute__((__noreturn__)) usage(int status)
{
FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 93a3843c7..756343beb 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -2041,12 +2041,12 @@ static void termio_final(struct options *op, struct termios *tp, struct chardata
case 1:
/* odd parity */
tp->c_cflag |= PARODD;
- /* do not break */
+ UL_FALLTHROUGH;
case 2:
/* even parity */
tp->c_cflag |= PARENB;
tp->c_iflag |= INPCK | ISTRIP;
- /* do not break */
+ UL_FALLTHROUGH;
case (1 | 2):
/* no parity bit */
tp->c_cflag &= ~CSIZE;
diff --git a/term-utils/script.c b/term-utils/script.c
index f2fc2f59c..ed7727ed9 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -389,9 +389,9 @@ static void handle_signal(struct script_control *ctl, int fd)
}
break;
case SIGTERM:
- /* fallthrough */
+ UL_FALLTHROUGH;
case SIGINT:
- /* fallthrough */
+ UL_FALLTHROUGH;
case SIGQUIT:
DBG(SIGNAL, ul_debug(" get signal SIG{TERM,INT,QUIT}"));
fprintf(stderr, _("\nSession terminated.\n"));
diff --git a/text-utils/hexdump-parse.c b/text-utils/hexdump-parse.c
index c60a4d06b..799877704 100644
--- a/text-utils/hexdump-parse.c
+++ b/text-utils/hexdump-parse.c
@@ -351,7 +351,7 @@ isint: cs[3] = '\0';
case 'A':
endfu = fu;
fu->flags |= F_IGNORE;
- /* FALLTHROUGH */
+ UL_FALLTHROUGH;
case 'a':
pr->flags = F_ADDRESS;
++p2;
diff --git a/text-utils/more.c b/text-utils/more.c
index 72dd96bf4..4a358850a 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -1270,7 +1270,7 @@ int command(char *filename, register FILE *f)
break;
}
lastp++;
- /* fall through */
+ UL_FALLTHROUGH;
case '/':
if (nlines == 0)
nlines++;
@@ -1368,7 +1368,7 @@ int command(char *filename, register FILE *f)
(char *)0);
break;
}
- /* fall through */
+ UL_FALLTHROUGH;
default:
if (dum_opt) {
kill_line();
@@ -2023,6 +2023,7 @@ int expand(char **outbuf, char *inbuf)
*outstr++ = *inpstr++;
break;
}
+ UL_FALLTHROUGH;
default:
*outstr++ = c;
}
diff --git a/text-utils/pg.c b/text-utils/pg.c
index 1b9b8d7dd..7608a0c45 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -659,7 +659,7 @@ static void prompt(long long pageno)
break;
case SEARCH_FIN:
state = SEARCH;
- /* FALLTHRU */
+ UL_FALLTHROUGH;
case SEARCH:
if (cmd.cmdline[cmd.cmdlen - 1] == '\\') {
escape = 1;
@@ -738,7 +738,7 @@ static void prompt(long long pageno)
continue;
}
state = COUNT;
- /* FALLTHRU */
+ UL_FALLTHROUGH;
case COUNT:
break;
case ADDON_FIN:
diff --git a/text-utils/ul.c b/text-utils/ul.c
index 3986b4206..79e6bdbc5 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
default:
warnx(_("trouble reading terminfo"));
- /* fall through to ... */
+ UL_FALLTHROUGH;
case 0:
if (tflag)
@@ -317,7 +317,7 @@ static void filter(FILE *f)
}
obuf[col].c_char = '_';
obuf[col].c_width = 1;
- /* fall through */
+ UL_FALLTHROUGH;
case ' ':
setcol(col + 1);
continue;
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 02/11] line: do not print new line if nothing else was printed
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
2017-06-08 19:52 ` [PATCH 01/11] misc: fallthrough fixes Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-09 12:01 ` Ruediger Meier
2017-06-08 19:52 ` [PATCH 03/11] rename: notice when expression and replacement are the same string Sami Kerola
` (9 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Earlier the following printed stray new line.
$ printf "" | ./line
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/line.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/text-utils/line.c b/text-utils/line.c
index 486e5dd31..ae10809c2 100644
--- a/text-utils/line.c
+++ b/text-utils/line.c
@@ -42,7 +42,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
int main(int argc, char **argv)
{
wint_t c;
- int opt;
+ int opt, print_nl = 0;
int status = EXIT_SUCCESS;
static const struct option longopts[] = {
@@ -77,8 +77,10 @@ int main(int argc, char **argv)
if (c == '\n')
break;
putwchar(c);
+ print_nl = 1;
}
- putwchar(L'\n');
+ if (print_nl)
+ putwchar(L'\n');
return status;
}
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 03/11] rename: notice when expression and replacement are the same string
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
2017-06-08 19:52 ` [PATCH 01/11] misc: fallthrough fixes Sami Kerola
2017-06-08 19:52 ` [PATCH 02/11] line: do not print new line if nothing else was printed Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 04/11] uuidgen: slice up the usage text Sami Kerola
` (8 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The rename(1) can exit early when replace expression and replacement are
identical string. It is also appropriate to change return value in this
case to 'nothing was renamed'.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/rename.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/misc-utils/rename.c b/misc-utils/rename.c
index a7671fa11..1cee40697 100644
--- a/misc-utils/rename.c
+++ b/misc-utils/rename.c
@@ -204,6 +204,9 @@ int main(int argc, char **argv)
from = argv[0];
to = argv[1];
+ if (!strcmp(from, to))
+ return RENAME_EXIT_NOTHING;
+
for (i = 2; i < argc; i++)
ret |= do_rename(from, to, argv[i], verbose, noact, nooverwrite);
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 04/11] uuidgen: slice up the usage text
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (2 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 03/11] rename: notice when expression and replacement are the same string Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated Sami Kerola
` (7 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/uuidgen.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 911fead72..4c1d47d5e 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -28,11 +28,11 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(_("Create a new UUID value.\n"), out);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -r, --random generate random-based uuid\n"
- " -t, --time generate time-based uuid\n"
- " -V, --version output version information and exit\n"
- " -h, --help display this help and exit\n\n"), out);
-
+ fputs(_(" -r, --random generate random-based uuid\n"), out);
+ fputs(_(" -t, --time generate time-based uuid\n"), out);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("uuidgen(1)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (3 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 04/11] uuidgen: slice up the usage text Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-13 13:16 ` Karel Zak
2017-06-08 19:52 ` [PATCH 06/11] isosize: avoid reading more data than what is needed Sami Kerola
` (6 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The uuidgen has always had option to use time as a uuid value. To common
users these timestamps have been difficult to convert to readable format, so
add an option to do that.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/uuidgen | 5 ++++-
misc-utils/Makemodule.am | 2 +-
misc-utils/uuidgen.1 | 8 ++++++++
misc-utils/uuidgen.c | 41 +++++++++++++++++++++++++++++++++++++++--
tests/expected/uuid/uuidgen | 6 ++++++
tests/ts/uuid/uuidgen | 10 ++++++++++
6 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/bash-completion/uuidgen b/bash-completion/uuidgen
index 42d95d42f..729e9621d 100644
--- a/bash-completion/uuidgen
+++ b/bash-completion/uuidgen
@@ -8,10 +8,13 @@ _uuidgen_module()
'-h'|'--help'|'-V'|'--version')
return 0
;;
+ '--date')
+ COMPREPLY=( $(compgen -W "uuid" -- $cur) )
+ ;;
esac
case $cur in
-*)
- OPTS="--random --time --version --help"
+ OPTS="--random --time --date --version --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index f28261c8b..38f799ddd 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -84,7 +84,7 @@ if BUILD_UUIDGEN
usrbin_exec_PROGRAMS += uuidgen
dist_man_MANS += misc-utils/uuidgen.1
uuidgen_SOURCES = misc-utils/uuidgen.c
-uuidgen_LDADD = $(LDADD) libuuid.la
+uuidgen_LDADD = $(LDADD) libuuid.la libcommon.la
uuidgen_CFLAGS = $(AM_CFLAGS) -I$(ul_libuuid_incdir)
endif
diff --git a/misc-utils/uuidgen.1 b/misc-utils/uuidgen.1
index 56c2bc7bd..a67e22c08 100644
--- a/misc-utils/uuidgen.1
+++ b/misc-utils/uuidgen.1
@@ -42,6 +42,14 @@ quality random number generator, such as
Generate a time-based UUID. This method creates a UUID based on the system
clock plus the system's ethernet hardware address, if present.
.TP
+.BI "\-\-date " uuid
+Display when a time-based UUID was generated. If there are additional
+command-line arguments they are printed as well.
+.PP
+Notice that there is no way to know by looking an UUID if it is time or
+random based. Both types are converted, and random-based UUIDs tend to have
+values mostly in future, but sometimes in past.
+.TP
.BR \-h , " \-\-help"
Display help text and exit.
.TP
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 4c1d47d5e..5a43af5c3 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -17,6 +17,7 @@
#include "nls.h"
#include "c.h"
#include "closestream.h"
+#include "timeutils.h"
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -28,8 +29,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(_("Create a new UUID value.\n"), out);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -r, --random generate random-based uuid\n"), out);
- fputs(_(" -t, --time generate time-based uuid\n"), out);
+ fputs(_(" -r, --random generate random-based uuid\n"), out);
+ fputs(_(" -t, --time generate time-based uuid\n"), out);
+ fputs(_(" --date <uuid> display when uuid was generated\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
@@ -37,6 +39,23 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
+static int print_uuid_date(char *date)
+{
+ uuid_t uuid;
+ struct timeval tv;
+ char buf[ISO_8601_BUFSIZ];
+
+ if (uuid_parse(date, uuid)) {
+ printf(_("invalid uuid: %s\n"), date);
+ return 1;
+ }
+ uuid_time(uuid, &tv);
+ strtimeval_iso(&tv, ISO_8601_DATE | ISO_8601_TIME | ISO_8601_COMMAUSEC |
+ ISO_8601_TIMEZONE | ISO_8601_SPACE, buf, sizeof(buf));
+ printf("%s\n", buf);
+ return 0;
+}
+
int
main (int argc, char *argv[])
{
@@ -44,10 +63,16 @@ main (int argc, char *argv[])
int do_type = 0;
char str[37];
uuid_t uu;
+ int print_dates = 0;
+ int valid_uuids = 0;
+ enum {
+ OPT_DATE = CHAR_MAX + 1,
+ };
static const struct option longopts[] = {
{"random", no_argument, NULL, 'r'},
{"time", no_argument, NULL, 't'},
+ {"date", required_argument, NULL, OPT_DATE},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
@@ -60,6 +85,10 @@ main (int argc, char *argv[])
while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
switch (c) {
+ case OPT_DATE:
+ valid_uuids |= print_uuid_date(optarg);
+ print_dates = 1;
+ break;
case 't':
do_type = UUID_TYPE_DCE_TIME;
break;
@@ -75,6 +104,14 @@ main (int argc, char *argv[])
errtryhelp(EXIT_FAILURE);
}
+ if (print_dates) {
+ for (; optind < argc; optind++)
+ valid_uuids |= print_uuid_date(argv[optind]);
+ if (valid_uuids)
+ return EXIT_FAILURE;
+ return EXIT_SUCCESS;
+ }
+
switch (do_type) {
case UUID_TYPE_DCE_TIME:
uuid_generate_time(uu);
diff --git a/tests/expected/uuid/uuidgen b/tests/expected/uuid/uuidgen
index b0d1d98e7..00ea3f2d2 100644
--- a/tests/expected/uuid/uuidgen
+++ b/tests/expected/uuid/uuidgen
@@ -6,3 +6,9 @@ option: --random
return values: 0 and 0
option: --time
return values: 0 and 0
+test --date
+2017-05-21 17:25:32,471528+0000
+2017-05-21 17:50:52,171166+0000
+invalid uuid: 080fc42c-3e4e-11e7-8ba8-00037f50000
+invalid uuid: 080fc42c-3e4e-11e7-8ba8-00037f50000g
+return value: 1
diff --git a/tests/ts/uuid/uuidgen b/tests/ts/uuid/uuidgen
index 6aa1b5b21..1514afc5c 100755
--- a/tests/ts/uuid/uuidgen
+++ b/tests/ts/uuid/uuidgen
@@ -40,6 +40,16 @@ test_flag -t
test_flag --random
test_flag --time
+export TZ=GMT
+echo "test --date" >> $TS_OUTPUT
+$TS_CMD_UUIDGEN --date \
+ 7e400110-3e4a-11e7-8af1-00037f500001 \
+ 080fc42c-3e4e-11e7-8ba8-00037f500001 \
+ 080fc42c-3e4e-11e7-8ba8-00037f50000 \
+ 080fc42c-3e4e-11e7-8ba8-00037f50000g \
+ >> "$TS_OUTPUT" 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+
rm -f "$OUTPUT_FILE"
ts_finalize
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 06/11] isosize: avoid reading more data than what is needed
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (4 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 07/11] misc: fix reassigned values before old ones has been used [cppcheck] Sami Kerola
` (5 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
In same go fix error reporting when input file is not long enough.
$ touch empty
$ isosize empty
isosize: empty: might not be an ISO filesystem
isosize: read error on empty: Success
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/isosize.c | 57 +++++++++-------------------------------------------
1 file changed, 10 insertions(+), 47 deletions(-)
diff --git a/disk-utils/isosize.c b/disk-utils/isosize.c
index d3d11c921..b5ac56262 100644
--- a/disk-utils/isosize.c
+++ b/disk-utils/isosize.c
@@ -30,8 +30,6 @@
#include "strutils.h"
#include "closestream.h"
-#define ISODCL(from, to) (to - from + 1)
-
static int is_iso(int fd)
{
char label[8];
@@ -88,62 +86,27 @@ static int isonum_733(unsigned char *p, int xflag)
return (le);
}
-struct iso_primary_descriptor
-{
- unsigned char type [ISODCL ( 1, 1)]; /* 711 */
- unsigned char id [ISODCL ( 2, 6)];
- unsigned char version [ISODCL ( 7, 7)]; /* 711 */
- unsigned char unused1 [ISODCL ( 8, 8)];
- unsigned char system_id [ISODCL ( 9, 40)]; /* auchars */
- unsigned char volume_id [ISODCL ( 41, 72)]; /* duchars */
- unsigned char unused2 [ISODCL ( 73, 80)];
- unsigned char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
- unsigned char unused3 [ISODCL ( 89, 120)];
- unsigned char volume_set_size [ISODCL ( 121, 124)]; /* 723 */
- unsigned char volume_sequence_number [ISODCL ( 125, 128)]; /* 723 */
- unsigned char logical_block_size [ISODCL ( 129, 132)]; /* 723 */
- unsigned char path_table_size [ISODCL ( 133, 140)]; /* 733 */
- unsigned char type_l_path_table [ISODCL ( 141, 144)]; /* 731 */
- unsigned char opt_type_l_path_table [ISODCL ( 145, 148)]; /* 731 */
- unsigned char type_m_path_table [ISODCL ( 149, 152)]; /* 732 */
- unsigned char opt_type_m_path_table [ISODCL ( 153, 156)]; /* 732 */
- unsigned char root_directory_record [ISODCL ( 157, 190)]; /* 9.1 */
- unsigned char volume_set_id [ISODCL ( 191, 318)]; /* duchars */
- unsigned char publisher_id [ISODCL ( 319, 446)]; /* achars */
- unsigned char preparer_id [ISODCL ( 447, 574)]; /* achars */
- unsigned char application_id [ISODCL ( 575, 702)]; /* achars */
- unsigned char copyright_file_id [ISODCL ( 703, 739)]; /* 7.5 dchars */
- unsigned char abstract_file_id [ISODCL ( 740, 776)]; /* 7.5 dchars */
- unsigned char bibliographic_file_id [ISODCL ( 777, 813)]; /* 7.5 dchars */
- unsigned char creation_date [ISODCL ( 814, 830)]; /* 8.4.26.1 */
- unsigned char modification_date [ISODCL ( 831, 847)]; /* 8.4.26.1 */
- unsigned char expiration_date [ISODCL ( 848, 864)]; /* 8.4.26.1 */
- unsigned char effective_date [ISODCL ( 865, 881)]; /* 8.4.26.1 */
- unsigned char file_structure_version [ISODCL ( 882, 882)]; /* 711 */
- unsigned char unused4 [ISODCL ( 883, 883)];
- unsigned char application_data [ISODCL ( 884, 1395)];
- unsigned char unused5 [ISODCL (1396, 2048)];
-};
-
static void isosize(int argc, char *filenamep, int xflag, long divisor)
{
int fd, nsecs, ssize;
- struct iso_primary_descriptor ipd;
+ unsigned char volume_space_size[8];
+ unsigned char logical_block_size[4];
if ((fd = open(filenamep, O_RDONLY)) < 0)
err(EXIT_FAILURE, _("cannot open %s"), filenamep);
if (is_iso(fd))
warnx(_("%s: might not be an ISO filesystem"), filenamep);
- if (lseek(fd, 16 << 11, 0) == (off_t) - 1)
- err(EXIT_FAILURE, _("seek error on %s"), filenamep);
-
- if (read(fd, &ipd, sizeof(ipd)) <= 0)
- err(EXIT_FAILURE, _("read error on %s"), filenamep);
+ if (pread(fd, volume_space_size, sizeof(volume_space_size), 0x8050) <= 0 ||
+ pread(fd, logical_block_size, sizeof(logical_block_size), 0x8080) <= 0) {
+ if (errno)
+ err(EXIT_FAILURE, _("read error on %s"), filenamep);
+ errx(EXIT_FAILURE, _("read error on %s"), filenamep);
+ }
- nsecs = isonum_733(ipd.volume_space_size, xflag);
+ nsecs = isonum_733(volume_space_size, xflag);
/* isonum_723 returns nowadays always 2048 */
- ssize = isonum_723(ipd.logical_block_size, xflag);
+ ssize = isonum_723(logical_block_size, xflag);
if (1 < argc)
printf("%s: ", filenamep);
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 07/11] misc: fix reassigned values before old ones has been used [cppcheck]
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (5 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 06/11] isosize: avoid reading more data than what is needed Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 08/11] losetup: add missing initializer [clang] Sami Kerola
` (4 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/cfdisk.c | 2 +-
libblkid/src/devno.c | 2 +-
libblkid/src/probe.c | 2 +-
libfdisk/src/gpt.c | 2 +-
libfdisk/src/script.c | 2 +-
libmount/src/btrfs.c | 2 +-
libmount/src/cache.c | 6 +++---
libmount/src/context.c | 2 +-
libmount/src/context_umount.c | 2 +-
libmount/src/optstr.c | 2 +-
libmount/src/tab_diff.c | 4 ++--
libmount/src/tab_update.c | 2 +-
libsmartcols/src/column.c | 2 +-
misc-utils/findmnt-verify.c | 2 +-
misc-utils/findmnt.c | 8 ++++----
sys-utils/losetup.c | 2 +-
sys-utils/swapon.c | 2 +-
17 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 1b2bc11fb..b09ae8f7b 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -323,7 +323,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
{
struct fdisk_partition *pa;
struct fdisk_label *lb;
- struct fdisk_iter *itr = NULL;
+ struct fdisk_iter *itr;
struct libscols_table *table = NULL;
struct libscols_iter *s_itr = NULL;
char *res = NULL;
diff --git a/libblkid/src/devno.c b/libblkid/src/devno.c
index 71eb4a533..8882cddad 100644
--- a/libblkid/src/devno.c
+++ b/libblkid/src/devno.c
@@ -225,7 +225,7 @@ static char *scandev_devno_to_devpath(dev_t devno)
*/
char *blkid_devno_to_devname(dev_t devno)
{
- char *path = NULL;
+ char *path;
char buf[PATH_MAX];
path = sysfs_devno_to_devpath(devno, buf, sizeof(buf));
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 7eaceac6d..77c46cccc 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -206,7 +206,7 @@ blkid_probe blkid_clone_probe(blkid_probe parent)
*/
blkid_probe blkid_new_probe_from_filename(const char *filename)
{
- int fd = -1;
+ int fd;
blkid_probe pr = NULL;
fd = open(filename, O_RDONLY|O_CLOEXEC);
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index 6b894aa23..249feb74d 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -1913,7 +1913,7 @@ fail:
static int gpt_write_pmbr(struct fdisk_context *cxt)
{
off_t offset;
- struct gpt_legacy_mbr *pmbr = NULL;
+ struct gpt_legacy_mbr *pmbr;
assert(cxt);
assert(cxt->firstsector);
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index 198e9edb9..be325bc09 100644
--- a/libfdisk/src/script.c
+++ b/libfdisk/src/script.c
@@ -1528,7 +1528,7 @@ static int test_apply(struct fdisk_test *ts, int argc, char *argv[])
{
char *devname = argv[1], *scriptname = argv[2];
struct fdisk_context *cxt;
- struct fdisk_script *dp = NULL;
+ struct fdisk_script *dp;
struct fdisk_table *tb = NULL;
struct fdisk_iter *itr = NULL;
struct fdisk_partition *pa = NULL;
diff --git a/libmount/src/btrfs.c b/libmount/src/btrfs.c
index be4d144bf..0b09053bb 100644
--- a/libmount/src/btrfs.c
+++ b/libmount/src/btrfs.c
@@ -105,7 +105,7 @@ uint64_t btrfs_get_default_subvol_id(const char *path)
{
int iocret;
int fd;
- DIR *dirstream = NULL;
+ DIR *dirstream;
struct btrfs_ioctl_search_args args;
struct btrfs_ioctl_search_key *sk = &args.key;
struct btrfs_ioctl_search_header *sh;
diff --git a/libmount/src/cache.c b/libmount/src/cache.c
index 6ff997140..b52ca8098 100644
--- a/libmount/src/cache.c
+++ b/libmount/src/cache.c
@@ -489,9 +489,9 @@ char *mnt_get_fstype(const char *devname, int *ambi, struct libmnt_cache *cache)
static char *canonicalize_path_and_cache(const char *path,
struct libmnt_cache *cache)
{
- char *p = NULL;
- char *key = NULL;
- char *value = NULL;
+ char *p;
+ char *key;
+ char *value;
DBG(CACHE, ul_debugobj(cache, "canonicalize path %s", path));
p = canonicalize_path(path);
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 5725ab1ad..fdbb02585 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -1965,7 +1965,7 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb,
int direction)
{
struct libmnt_fs *fs = NULL;
- const char *src = NULL, *tgt = NULL;
+ const char *src, *tgt;
int rc;
assert(cxt);
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 4a4c5bfe5..a97c28ba6 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -478,7 +478,7 @@ static int evaluate_permissions(struct libmnt_context *cxt)
*/
if (u_flags & (MNT_MS_USER | MNT_MS_OWNER | MNT_MS_GROUP)) {
- char *curr_user = NULL;
+ char *curr_user;
char *mtab_user = NULL;
size_t sz;
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 4b9622ed5..8248f0dee 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -382,7 +382,7 @@ insert_value(char **str, char *pos, const char *substr, char **next)
size_t strsz = strlen(*str);
size_t possz = strlen(pos);
size_t posoff;
- char *p = NULL;
+ char *p;
int sep;
/* is it necessary to prepend '=' before the substring ? */
diff --git a/libmount/src/tab_diff.c b/libmount/src/tab_diff.c
index 7cf9e57ef..6caaa2a2d 100644
--- a/libmount/src/tab_diff.c
+++ b/libmount/src/tab_diff.c
@@ -305,8 +305,8 @@ done:
static int test_diff(struct libmnt_test *ts, int argc, char *argv[])
{
- struct libmnt_table *tb_old = NULL, *tb_new = NULL;
- struct libmnt_tabdiff *diff = NULL;
+ struct libmnt_table *tb_old, *tb_new;
+ struct libmnt_tabdiff *diff;
struct libmnt_iter *itr;
struct libmnt_fs *old, *new;
int rc = -1, change;
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c
index d85cb89da..52e1dd444 100644
--- a/libmount/src/tab_update.c
+++ b/libmount/src/tab_update.c
@@ -291,7 +291,7 @@ static int utab_new_entry(struct libmnt_update *upd, struct libmnt_fs *fs,
unsigned long mountflags)
{
int rc = 0;
- const char *o = NULL, *a = NULL;
+ const char *o, *a;
char *u = NULL;
assert(fs);
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index 1d3287960..ce1ed7e22 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -293,7 +293,7 @@ size_t scols_wrapnl_chunksize(const struct libscols_column *cl __attribute__((un
size_t sum = 0;
while (data && *data) {
- const char *p = data;
+ const char *p;
size_t sz;
p = strchr(data, '\n');
diff --git a/misc-utils/findmnt-verify.c b/misc-utils/findmnt-verify.c
index e3fb391d4..b32901d66 100644
--- a/misc-utils/findmnt-verify.c
+++ b/misc-utils/findmnt-verify.c
@@ -472,7 +472,7 @@ static int verify_filesystem(struct verify_context *vfy)
int verify_table(struct libmnt_table *tb)
{
struct verify_context vfy = { .nerrors = 0 };
- struct libmnt_iter *itr = NULL;
+ struct libmnt_iter *itr;
int rc = 0; /* overall return code (alloc errors, etc.) */
int check_order = is_listall_mode();
static int has_read_fs = 0;
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 5b8d345b1..db9b5c24e 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -873,7 +873,7 @@ static void cache_set_targets(struct libmnt_cache *tmp)
static int tab_is_tree(struct libmnt_table *tb)
{
struct libmnt_fs *fs = NULL;
- struct libmnt_iter *itr = NULL;
+ struct libmnt_iter *itr;
int rc = 0;
itr = mnt_new_iter(MNT_ITER_BACKWARD);
@@ -892,7 +892,7 @@ static int tab_is_tree(struct libmnt_table *tb)
static int tab_is_kernel(struct libmnt_table *tb)
{
struct libmnt_fs *fs = NULL;
- struct libmnt_iter *itr = NULL;
+ struct libmnt_iter *itr;
itr = mnt_new_iter(MNT_ITER_BACKWARD);
if (!itr)
@@ -1008,7 +1008,7 @@ again:
static int add_matching_lines(struct libmnt_table *tb,
struct libscols_table *table, int direction)
{
- struct libmnt_iter *itr = NULL;
+ struct libmnt_iter *itr;
struct libmnt_fs *fs;
int nlines = 0, rc = -1;
@@ -1068,7 +1068,7 @@ static int poll_table(struct libmnt_table *tb, const char *tabfile,
FILE *f = NULL;
int rc = -1;
struct libmnt_iter *itr = NULL;
- struct libmnt_table *tb_new = NULL;
+ struct libmnt_table *tb_new;
struct libmnt_tabdiff *diff = NULL;
struct pollfd fds[1];
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 8a9bdf55d..e0676c9fd 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -113,7 +113,7 @@ static int printf_loopdev(struct loopdev_cxt *lc)
uint64_t x;
dev_t dev = 0;
ino_t ino = 0;
- char *fname = NULL;
+ char *fname;
uint32_t type;
fname = loopcxt_get_backing_file(lc);
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index f4ca781d8..6bd057dd2 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -501,7 +501,7 @@ static void swap_get_info(struct swap_device *dev, const char *hdr)
static int swapon_checks(const struct swapon_ctl *ctl, struct swap_device *dev)
{
struct stat st;
- int fd = -1, sig;
+ int fd, sig;
char *hdr = NULL;
unsigned long long devsize = 0;
int permMask;
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 08/11] losetup: add missing initializer [clang]
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (6 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 07/11] misc: fix reassigned values before old ones has been used [cppcheck] Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 09/11] misc: remove stray semicolons Sami Kerola
` (3 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
FIXME: I am not entirely sure if rc should be initialized to 1 or 0.
sys-utils/losetup.c:290:12: warning: variable 'rc' is used uninitialized
whenever 'if' condition is false [-Wsometimes-uninitialized]
sys-utils/losetup.c:293:7: note: uninitialized use occurs here
sys-utils/losetup.c:290:8: note: remove the 'if' if its condition is always true
sys-utils/losetup.c:228:9: note: initialize the variable 'rc' to silence
this warning
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/losetup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index e0676c9fd..8ed9a1e4b 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -225,7 +225,7 @@ static int set_scols_data(struct loopdev_cxt *lc, struct libscols_line *ln)
const char *p = NULL; /* external data */
char *np = NULL; /* allocated here */
uint64_t x = 0;
- int rc;
+ int rc = 0;
switch(get_column_id(i)) {
case COL_NAME:
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 09/11] misc: remove stray semicolons
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (7 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 08/11] losetup: add missing initializer [clang] Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 10/11] lib: simplify cpuset if clauses that return Sami Kerola
` (2 subsequent siblings)
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
lib/mbsalign.c | 2 +-
libblkid/src/superblocks/adaptec_raid.c | 2 +-
libmount/src/btrfs.c | 4 ++--
libmount/src/context_mount.c | 2 +-
libmount/src/context_umount.c | 2 +-
libsmartcols/src/column.c | 2 +-
misc-utils/test_uuidd.c | 2 +-
sys-utils/unshare.c | 2 +-
term-utils/wall.c | 2 +-
text-utils/column.c | 2 +-
10 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index 731320b07..b0e1004a0 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -206,7 +206,7 @@ size_t mbs_safe_encode_size(size_t bytes)
char *mbs_safe_encode(const char *s, size_t *width)
{
size_t sz = s ? strlen(s) : 0;
- char *buf, *ret = NULL;;
+ char *buf, *ret = NULL;
if (!sz)
return NULL;
diff --git a/libblkid/src/superblocks/adaptec_raid.c b/libblkid/src/superblocks/adaptec_raid.c
index 65fd5b8b4..5fc5fc4bc 100644
--- a/libblkid/src/superblocks/adaptec_raid.c
+++ b/libblkid/src/superblocks/adaptec_raid.c
@@ -91,7 +91,7 @@ static int probe_adraid(blkid_probe pr,
off,
sizeof(struct adaptec_metadata));
if (!ad)
- return errno ? -errno : BLKID_PROBE_NONE;;
+ return errno ? -errno : BLKID_PROBE_NONE;
if (ad->smagic != be32_to_cpu(AD_SIGNATURE))
return BLKID_PROBE_NONE;
diff --git a/libmount/src/btrfs.c b/libmount/src/btrfs.c
index 0b09053bb..1669c2722 100644
--- a/libmount/src/btrfs.c
+++ b/libmount/src/btrfs.c
@@ -75,9 +75,9 @@ static inline void btrfs_set_##name(type *s, uint##bits##_t val) \
/* struct btrfs_disk_key */
BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
- objectid, 64);
+ objectid, 64)
-BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16);
+BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16)
/*
Red Black Trees
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index 9caee70e5..2c5334217 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -1042,7 +1042,7 @@ int mnt_context_finalize_mount(struct libmnt_context *cxt)
rc = mnt_context_prepare_update(cxt);
if (!rc)
- rc = mnt_context_update_tabs(cxt);;
+ rc = mnt_context_update_tabs(cxt);
return rc;
}
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index a97c28ba6..1548fff72 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -889,7 +889,7 @@ int mnt_context_finalize_umount(struct libmnt_context *cxt)
rc = mnt_context_prepare_update(cxt);
if (!rc)
- rc = mnt_context_update_tabs(cxt);;
+ rc = mnt_context_update_tabs(cxt);
return rc;
}
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index ce1ed7e22..ba6c31920 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -304,7 +304,7 @@ size_t scols_wrapnl_chunksize(const struct libscols_column *cl __attribute__((un
sz = mbs_safe_width(data);
sum = max(sum, sz);
- data = p;;
+ data = p;
}
return sum;
diff --git a/misc-utils/test_uuidd.c b/misc-utils/test_uuidd.c
index 9883cbf29..26751a485 100644
--- a/misc-utils/test_uuidd.c
+++ b/misc-utils/test_uuidd.c
@@ -143,7 +143,7 @@ static void *create_uuids(thread_t *th)
object_uuid_create(obj);
obj->tid = th->tid;
obj->pid = th->proc->pid;
- obj->idx = th->index + i;;
+ obj->idx = th->index + i;
}
return NULL;
}
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index 6c5c2e2f9..80fa0d356 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -308,7 +308,7 @@ int main(int argc, char *argv[])
int status;
unsigned long propagation = UNSHARE_PROPAGATION_DEFAULT;
uid_t real_euid = geteuid();
- gid_t real_egid = getegid();;
+ gid_t real_egid = getegid();
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
diff --git a/term-utils/wall.c b/term-utils/wall.c
index a9dde15be..fa2ec2143 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -303,7 +303,7 @@ static void buf_printf(struct buffer *bs, const char *fmt, ...)
buf_enlarge(bs, (size_t)rc + 1);
limit = bs->sz - bs->used;
va_start(ap, fmt);
- rc = vsnprintf(bs->data + bs->used, limit, fmt, ap);;
+ rc = vsnprintf(bs->data + bs->used, limit, fmt, ap);
va_end(ap);
}
diff --git a/text-utils/column.c b/text-utils/column.c
index c315f91ef..9f9eabaa8 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -482,7 +482,7 @@ static void columnate_fillrows(struct column_control *ctl)
ctl->maxlength = (ctl->maxlength + TABCHAR_CELLS) & ~(TABCHAR_CELLS - 1);
numcols = ctl->termwidth / ctl->maxlength;
endcol = ctl->maxlength;
- for (chcnt = col = 0, lp = ctl->ents;; ++lp) {
+ for (chcnt = col = 0, lp = ctl->ents; /* nothing */; ++lp) {
fputws(*lp, stdout);
chcnt += width(*lp);
if (!--ctl->nents)
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 10/11] lib: simplify cpuset if clauses that return
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (8 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 09/11] misc: remove stray semicolons Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 11/11] lib: remove _RLD_ from forbid environment variable list Sami Kerola
2017-06-14 10:30 ` [PATCH 00/11] pull: various small changes Karel Zak
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
There is no need for 'else' when 'if' will return. In same go move call of
tolower() to last possible moment in char_to_val(), a lot of time hex values
should hit 0-9 range, and it can be omitted.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
lib/cpuset.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 6d82522f5..011b6882b 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -29,23 +29,21 @@ static inline int val_to_char(int v)
{
if (v >= 0 && v < 10)
return '0' + v;
- else if (v >= 10 && v < 16)
+ if (v >= 10 && v < 16)
return ('a' - 10) + v;
- else
- return -1;
+ return -1;
}
static inline int char_to_val(int c)
{
int cl;
- cl = tolower(c);
if (c >= '0' && c <= '9')
return c - '0';
- else if (cl >= 'a' && cl <= 'f')
+ cl = tolower(c);
+ if (cl >= 'a' && cl <= 'f')
return cl + (10 - 'a');
- else
- return -1;
+ return -1;
}
static const char *nexttoken(const char *q, int sep)
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH 11/11] lib: remove _RLD_ from forbid environment variable list
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (9 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 10/11] lib: simplify cpuset if clauses that return Sami Kerola
@ 2017-06-08 19:52 ` Sami Kerola
2017-06-14 10:30 ` [PATCH 00/11] pull: various small changes Karel Zak
11 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-08 19:52 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The RLD environment variables are related to runtime linker vulnerability in
TELNET on systems running Silicon Graphics IRIX. It is extremely unlikely
current util-linux would be compiled on such system.
Reference: http://www.cert.org/historical/advisories/CA-1995-14.cfm
Reference: http://signatures.juniper.net/documentation/signatures/TELNET%3AEXPLOIT%3ASGI-RLD.html
Refefence: http://www.polarhome.com/service/man/?qf=rld&tf=2&of=IRIX&sf=1
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
lib/env.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/env.c b/lib/env.c
index c79e0e0de..b2e3d975a 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -26,7 +26,6 @@ extern char **environ;
#endif
static char * const forbid[] = {
- "_RLD_=",
"BASH_ENV=", /* GNU creeping featurism strikes again... */
"ENV=",
"HOME=",
--
2.13.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-08 19:52 ` [PATCH 01/11] misc: fallthrough fixes Sami Kerola
@ 2017-06-09 11:14 ` Ruediger Meier
2017-06-09 21:10 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Ruediger Meier @ 2017-06-09 11:14 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
Hi,
This patch looks a bit ugly, for example:
## gcc 4.8.1
CC text-utils/more-more.o
../text-utils/more.c: In function ‘command’:
../text-utils/more.c:1273:4: warning: empty declaration [enabled by
default]
UL_FALLTHROUGH;
## icc 16.0.0
text-utils/more.c(1273): warning #1292: unknown attribute "fallthrough"
UL_FALLTHROUGH;
^
> diff --git a/include/c.h b/include/c.h
> index a5162b964..8a67b5dfb 100644
> --- a/include/c.h
> +++ b/include/c.h
> @@ -77,6 +77,24 @@
> #endif
>
> /*
> + * Statement Attributes
> + */
> +#if defined(__clang__)
> +# ifndef __has_cpp_attribute
> +# define __has_cpp_attribute(x) 0
> +# endif
> +# if __has_cpp_attribute(clang::fallthrough)
> +# define UL_FALLTHROUGH [[clang::fallthrough]]
> +# else
> +# define UL_FALLTHROUGH /* fall through */
> +# endif
> +#elif defined(__GNUC__) || defined(__GNUG__)
> +# define UL_FALLTHROUGH __attribute__((fallthrough))
> +#else
> +# define UL_FALLTHROUGH /* FALLTHRU */
> +#endif
> +
> +/*
Maybe just simplify like this:
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#if __has_cpp_attribute(fallthrough)
# define UL_FALLTHROUGH [[fallthrough]]
#else
# define UL_FALLTHROUGH /* fall through */
#endif
The attribute works without "clang::" prefix on recent gcc and clang,
and maybe icc in future.
Otherwise we could check for the attribute in configure, using
autoconf-archive
AX_GCC_FUNC_ATTRIBUTE(fallthrough)
https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
cu,
Rudi
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 02/11] line: do not print new line if nothing else was printed
2017-06-08 19:52 ` [PATCH 02/11] line: do not print new line if nothing else was printed Sami Kerola
@ 2017-06-09 12:01 ` Ruediger Meier
2017-06-11 8:19 ` Sami Kerola
0 siblings, 1 reply; 31+ messages in thread
From: Ruediger Meier @ 2017-06-09 12:01 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Thursday 08 June 2017, Sami Kerola wrote:
> Earlier the following printed stray new line.
>
> $ printf "" | ./line
This breaks test "misc/line", see commit caad4ded
and
https://github.com/karelzak/util-linux/issues/236
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> text-utils/line.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/text-utils/line.c b/text-utils/line.c
> index 486e5dd31..ae10809c2 100644
> --- a/text-utils/line.c
> +++ b/text-utils/line.c
> @@ -42,7 +42,7 @@ static void __attribute__((__noreturn__))
> usage(FILE *out) int main(int argc, char **argv)
> {
> wint_t c;
> - int opt;
> + int opt, print_nl = 0;
> int status = EXIT_SUCCESS;
>
> static const struct option longopts[] = {
> @@ -77,8 +77,10 @@ int main(int argc, char **argv)
> if (c == '\n')
> break;
> putwchar(c);
> + print_nl = 1;
> }
> - putwchar(L'\n');
> + if (print_nl)
> + putwchar(L'\n');
>
> return status;
> }
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-09 11:14 ` Ruediger Meier
@ 2017-06-09 21:10 ` Rüdiger Meier
2017-06-11 8:36 ` Sami Kerola
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-09 21:10 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On 06/09/2017 01:14 PM, Ruediger Meier wrote:
> Hi,
>
> This patch looks a bit ugly, for example:
>
> ## gcc 4.8.1
>
> CC text-utils/more-more.o
> ../text-utils/more.c: In function ‘command’:
> ../text-utils/more.c:1273:4: warning: empty declaration [enabled by
> default]
> UL_FALLTHROUGH;
>
> ## icc 16.0.0
>
> text-utils/more.c(1273): warning #1292: unknown attribute "fallthrough"
> UL_FALLTHROUGH;
> ^
>
>> diff --git a/include/c.h b/include/c.h
>> index a5162b964..8a67b5dfb 100644
>> --- a/include/c.h
>> +++ b/include/c.h
>> @@ -77,6 +77,24 @@
>> #endif
>>
>> /*
>> + * Statement Attributes
>> + */
>> +#if defined(__clang__)
>> +# ifndef __has_cpp_attribute
>> +# define __has_cpp_attribute(x) 0
>> +# endif
>> +# if __has_cpp_attribute(clang::fallthrough)
>> +# define UL_FALLTHROUGH [[clang::fallthrough]]
>> +# else
>> +# define UL_FALLTHROUGH /* fall through */
>> +# endif
>> +#elif defined(__GNUC__) || defined(__GNUG__)
>> +# define UL_FALLTHROUGH __attribute__((fallthrough))
>> +#else
>> +# define UL_FALLTHROUGH /* FALLTHRU */
>> +#endif
>> +
>> +/*
Sorry this was broken. But I've checked now all clang and gcc versions. Looks
like for clang the warning is only enabled when using C++ (clang++). So the
fallthrough warning appears currently only on gcc>=7 and this works to disable
it in a compatible way:
#ifndef __has_cpp_attribute
# define __has_cpp_attribute(x) 0
#endif
#if __has_cpp_attribute(fallthrough)
# define UL_FALLTHROUGH __attribute__((fallthrough))
#else
# define UL_FALLTHROUGH /* fall through */
#endif
> Maybe just simplify like this:
>
> #ifndef __has_attribute
> #define __has_attribute(x) 0
> #endif
>
> #if __has_cpp_attribute(fallthrough)
> # define UL_FALLTHROUGH [[fallthrough]]
> #else
> # define UL_FALLTHROUGH /* fall through */
> #endif
>
> The attribute works without "clang::" prefix on recent gcc and clang,
> and maybe icc in future.
>
> Otherwise we could check for the attribute in configure, using
> autoconf-archive
> AX_GCC_FUNC_ATTRIBUTE(fallthrough)
> https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
>
> cu,
> Rudi
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 02/11] line: do not print new line if nothing else was printed
2017-06-09 12:01 ` Ruediger Meier
@ 2017-06-11 8:19 ` Sami Kerola
0 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-11 8:19 UTC (permalink / raw)
To: Ruediger Meier; +Cc: util-linux
On 9 June 2017 at 13:01, Ruediger Meier <sweet_f_a@gmx.de> wrote:
> On Thursday 08 June 2017, Sami Kerola wrote:
>> Earlier the following printed stray new line.
>>
>> $ printf "" | ./line
>
> This breaks test "misc/line", see commit caad4ded
> and
> https://github.com/karelzak/util-linux/issues/236
Thank you Rudi for noticing, the line(1) change is dropped from my
remote branch.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-09 21:10 ` Rüdiger Meier
@ 2017-06-11 8:36 ` Sami Kerola
2017-06-12 8:40 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Sami Kerola @ 2017-06-11 8:36 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: util-linux
On 9 June 2017 at 22:10, R=C3=BCdiger Meier <sweet_f_a@gmx.de> wrote:
>
>
> On 06/09/2017 01:14 PM, Ruediger Meier wrote:
>>
>> Hi,
>>
>> This patch looks a bit ugly, for example:
>>
>> ## gcc 4.8.1
>>
>> CC text-utils/more-more.o
>> ../text-utils/more.c: In function =E2=80=98command=E2=80=99:
>> ../text-utils/more.c:1273:4: warning: empty declaration [enabled by
>> default]
>> UL_FALLTHROUGH;
>>
>> ## icc 16.0.0
>>
>> text-utils/more.c(1273): warning #1292: unknown attribute "fallthrough"
>> UL_FALLTHROUGH;
>> ^
>>
>>> diff --git a/include/c.h b/include/c.h
>>> index a5162b964..8a67b5dfb 100644
>>> --- a/include/c.h
>>> +++ b/include/c.h
>>> @@ -77,6 +77,24 @@
>>> #endif
>>> /*
>>> + * Statement Attributes
>>> + */
>>> +#if defined(__clang__)
>>> +# ifndef __has_cpp_attribute
>>> +# define __has_cpp_attribute(x) 0
>>> +# endif
>>> +# if __has_cpp_attribute(clang::fallthrough)
>>> +# define UL_FALLTHROUGH [[clang::fallthrough]]
>>> +# else
>>> +# define UL_FALLTHROUGH /* fall through */
>>> +# endif
>>> +#elif defined(__GNUC__) || defined(__GNUG__)
>>> +# define UL_FALLTHROUGH __attribute__((fallthrough))
>>> +#else
>>> +# define UL_FALLTHROUGH /* FALLTHRU */
>>> +#endif
>>> +
>>> +/*
>
>
> Sorry this was broken. But I've checked now all clang and gcc versions.
> Looks
> like for clang the warning is only enabled when using C++ (clang++). So t=
he
> fallthrough warning appears currently only on gcc>=3D7 and this works to
> disable
> it in a compatible way:
>
> #ifndef __has_cpp_attribute
> # define __has_cpp_attribute(x) 0
> #endif
>
> #if __has_cpp_attribute(fallthrough)
> # define UL_FALLTHROUGH __attribute__((fallthrough))
> #else
> # define UL_FALLTHROUGH /* fall through */
> #endif
Thank you for review Rudi. I had a look of the c.h again and did the
change a little bit differently:
#ifdef __has_cpp_attribute
# if __has_cpp_attribute(deprecated)
# define UL_FALLTHROUGH __attribute__((fallthrough))
# elif __has_cpp_attribute(clang::fallthrough)
# define UL_FALLTHROUGH [[clang::fallthrough]]
# endif
#endif
#ifndef UL_FALLTHROUGH
# define UL_FALLTHROUGH /* FALLTHRU */
#endif
The above is now part of my remote branch '2017wk23'.
--=20
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-11 8:36 ` Sami Kerola
@ 2017-06-12 8:40 ` Rüdiger Meier
2017-06-12 21:54 ` Sami Kerola
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-12 8:40 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
Hi Sami,
On 06/11/2017 10:36 AM, Sami Kerola wrote:
> On 9 June 2017 at 22:10, Rüdiger Meier <sweet_f_a@gmx.de> wrote:
>> Sorry this was broken. But I've checked now all clang and gcc versions.
>> Looks
>> like for clang the warning is only enabled when using C++ (clang++). So the
>> fallthrough warning appears currently only on gcc>=7 and this works to
>> disable
>> it in a compatible way:
>>
>> #ifndef __has_cpp_attribute
>> # define __has_cpp_attribute(x) 0
>> #endif
>>
>> #if __has_cpp_attribute(fallthrough)
>> # define UL_FALLTHROUGH __attribute__((fallthrough))
>> #else
>> # define UL_FALLTHROUGH /* fall through */
>> #endif
>
> Thank you for review Rudi. I had a look of the c.h again and did the
> change a little bit differently:
>
> #ifdef __has_cpp_attribute
> # if __has_cpp_attribute(deprecated)
Is this a typoo? s/deprecated/fallthrough
> # define UL_FALLTHROUGH __attribute__((fallthrough))
> # elif __has_cpp_attribute(clang::fallthrough)
> # define UL_FALLTHROUGH [[clang::fallthrough]]
I still wonder. Have you really seen such a fallthrough warning from clang?
I've even tried with explicit -Wimplicit-fallthrough but could not get one.
As far as I understood these namespaced "clang::" attributes are for C++ only.
man clang:
Non-standard C++11 Attributes
Clang's non-standard C++11 attributes live in the clang attribute namespace
So IMO it makes no sense to use clang::fallthrough for C code.
> # endif
> #endif
> #ifndef UL_FALLTHROUGH
> # define UL_FALLTHROUGH /* FALLTHRU */
> #endif
BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to __ul_fallthrough
like we have already __ul_calloc_size. IMO it would look more obvious to the reader.
Also I would use it without semicolon because some compilers may complain about
useless ";" statements.
cu,
Rudi
> The above is now part of my remote branch '2017wk23'.
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-12 8:40 ` Rüdiger Meier
@ 2017-06-12 21:54 ` Sami Kerola
2017-06-12 23:16 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Sami Kerola @ 2017-06-12 21:54 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: util-linux
On 12 June 2017 at 09:40, R=C3=BCdiger Meier <sweet_f_a@gmx.de> wrote:
> On 06/11/2017 10:36 AM, Sami Kerola wrote:
>>
>> On 9 June 2017 at 22:10, R=C3=BCdiger Meier <sweet_f_a@gmx.de> wrote:
>
>
>>> Sorry this was broken. But I've checked now all clang and gcc versions.
>>> Looks
>>> like for clang the warning is only enabled when using C++ (clang++). So
>>> the
>>> fallthrough warning appears currently only on gcc>=3D7 and this works t=
o
>>> disable
>>> it in a compatible way:
>>>
>>> #ifndef __has_cpp_attribute
>>> # define __has_cpp_attribute(x) 0
>>> #endif
>>>
>>> #if __has_cpp_attribute(fallthrough)
>>> # define UL_FALLTHROUGH __attribute__((fallthrough))
>>> #else
>>> # define UL_FALLTHROUGH /* fall through */
>>> #endif
>>
>>
>> Thank you for review Rudi. I had a look of the c.h again and did the
>> change a little bit differently:
>>
>> #ifdef __has_cpp_attribute
>> # if __has_cpp_attribute(deprecated)
>
>
> Is this a typoo? s/deprecated/fallthrough
Hi Rudi,
Yes, it was a typo. Fixed in following.
https://github.com/kerolasa/lelux-utiliteetit/commit/aa1ed6ac309a2bd6f0c537=
1a3117618074e7634a
>> # define UL_FALLTHROUGH __attribute__((fallthrough))
>> # elif __has_cpp_attribute(clang::fallthrough)
>> # define UL_FALLTHROUGH [[clang::fallthrough]]
>
>
> I still wonder. Have you really seen such a fallthrough warning from clan=
g?
> I've even tried with explicit -Wimplicit-fallthrough but could not get on=
e.
>
> As far as I understood these namespaced "clang::" attributes are for C++
> only.
>
> man clang:
> Non-standard C++11 Attributes
> Clang's non-standard C++11 attributes live in the clang attribute
> namespace
>
> So IMO it makes no sense to use clang::fallthrough for C code.
Removed in same commit. Strange enough I'm pretty sure that attribute
worked.
>> # endif
>> #endif
>> #ifndef UL_FALLTHROUGH
>> # define UL_FALLTHROUGH /* FALLTHRU */
>> #endif
>
>
> BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
> __ul_fallthrough
> like we have already __ul_calloc_size. IMO it would look more obvious to =
the
> reader.
I don't have strong opinion about that, changed to one you proposed.
> Also I would use it without semicolon because some compilers may complain
> about
> useless ";" statements.
Semicolon is removed. Whether this will fool various indent tools is someth=
ing
to be seen.
--=20
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-12 21:54 ` Sami Kerola
@ 2017-06-12 23:16 ` Rüdiger Meier
2017-06-13 12:51 ` Karel Zak
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-12 23:16 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
On 06/12/2017 11:54 PM, Sami Kerola wrote:
> On 12 June 2017 at 09:40, Rüdiger Meier <sweet_f_a@gmx.de> wrote:
>> On 06/11/2017 10:36 AM, Sami Kerola wrote:
>>>
>>> On 9 June 2017 at 22:10, Rüdiger Meier <sweet_f_a@gmx.de> wrote:
>>
>>
>>>> Sorry this was broken. But I've checked now all clang and gcc versions.
>>>> Looks
>>>> like for clang the warning is only enabled when using C++ (clang++). So
>>>> the
>>>> fallthrough warning appears currently only on gcc>=7 and this works to
>>>> disable
>>>> it in a compatible way:
>>>>
>>>> #ifndef __has_cpp_attribute
>>>> # define __has_cpp_attribute(x) 0
>>>> #endif
>>>>
>>>> #if __has_cpp_attribute(fallthrough)
>>>> # define UL_FALLTHROUGH __attribute__((fallthrough))
>>>> #else
>>>> # define UL_FALLTHROUGH /* fall through */
>>>> #endif
>>>
>>>
>>> Thank you for review Rudi. I had a look of the c.h again and did the
>>> change a little bit differently:
>>>
>>> #ifdef __has_cpp_attribute
>>> # if __has_cpp_attribute(deprecated)
>>
>>
>> Is this a typoo? s/deprecated/fallthrough
>
> Hi Rudi,
>
> Yes, it was a typo. Fixed in following.
>
> https://github.com/kerolasa/lelux-utiliteetit/commit/aa1ed6ac309a2bd6f0c5371a3117618074e7634a
>
>>> # define UL_FALLTHROUGH __attribute__((fallthrough))
>>> # elif __has_cpp_attribute(clang::fallthrough)
>>> # define UL_FALLTHROUGH [[clang::fallthrough]]
>>
>>
>> I still wonder. Have you really seen such a fallthrough warning from clang?
>> I've even tried with explicit -Wimplicit-fallthrough but could not get one.
>>
>> As far as I understood these namespaced "clang::" attributes are for C++
>> only.
>>
>> man clang:
>> Non-standard C++11 Attributes
>> Clang's non-standard C++11 attributes live in the clang attribute
>> namespace
>>
>> So IMO it makes no sense to use clang::fallthrough for C code.
>
> Removed in same commit. Strange enough I'm pretty sure that attribute
> worked.
Yes, clang does not seem to complain about clang++ attributes. I guess they
don't want to introduce even more incompatibilities. Similar I've noticed
that even old gcc and clang compilers accept (ignore) the option
-Wimplicit-fallthrough" and probably any other warning option.
FYI I've set up a travis build script to test many gcc and clang versions.
The current build logs contain your and my other pull request
https://travis-ci.org/rudimeier/util-linux/builds/242109953
>>> # endif
>>> #endif
>>> #ifndef UL_FALLTHROUGH
>>> # define UL_FALLTHROUGH /* FALLTHRU */
>>> #endif
>>
>>
>> BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
>> __ul_fallthrough
>> like we have already __ul_calloc_size. IMO it would look more obvious to the
>> reader.
>
> I don't have strong opinion about that, changed to one you proposed.
Thanks, let's see whether Karel likes this attribute at all ;)
>> Also I would use it without semicolon because some compilers may complain
>> about
>> useless ";" statements.
>
> Semicolon is removed. Whether this will fool various indent tools is something
> to be seen.
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-12 23:16 ` Rüdiger Meier
@ 2017-06-13 12:51 ` Karel Zak
2017-06-13 13:03 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Karel Zak @ 2017-06-13 12:51 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: kerolasa, util-linux
On Tue, Jun 13, 2017 at 01:16:57AM +0200, Rüdiger Meier wrote:
> > > BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
> > > __ul_fallthrough
> > > like we have already __ul_calloc_size. IMO it would look more obvious to the
> > > reader.
> >
> > I don't have strong opinion about that, changed to one you proposed.
>
> Thanks, let's see whether Karel likes this attribute at all ;)
Hmm...
I don't like "meta-programming" where language keywords are
replaced by local macros, for example we have fallback (in c.h) for all
__attribute__ rather than define local macro for all attributes.
__attribute__((fallthrough))
should be fine on non-__GNUC__ as in this case __attribute__ is empty
macro (see c.h).
Yes, __ul_fallthrough seems better, and __attribute__((fallthrough))
would be the best :-)
It's strange if clang will use a different syntax for the same
things. IMHO it would be better to ignore clang for this attribute.
And I'm not sure if the change is compatible with coverity-scan where
comment line /* fallthrough */ is required, but this not so important
(coverity is maintained, so attribute will be supported one day...).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 12:51 ` Karel Zak
@ 2017-06-13 13:03 ` Rüdiger Meier
2017-06-13 13:41 ` Karel Zak
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-13 13:03 UTC (permalink / raw)
To: Karel Zak; +Cc: kerolasa, util-linux
On 06/13/2017 02:51 PM, Karel Zak wrote:
> On Tue, Jun 13, 2017 at 01:16:57AM +0200, Rüdiger Meier wrote:
>>>> BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
>>>> __ul_fallthrough
>>>> like we have already __ul_calloc_size. IMO it would look more obvious to the
>>>> reader.
>>>
>>> I don't have strong opinion about that, changed to one you proposed.
>>
>> Thanks, let's see whether Karel likes this attribute at all ;)
>
> Hmm...
>
> I don't like "meta-programming" where language keywords are
> replaced by local macros, for example we have fallback (in c.h) for all
> __attribute__ rather than define local macro for all attributes.
>
> __attribute__((fallthrough))
>
> should be fine on non-__GNUC__ as in this case __attribute__ is empty
> macro (see c.h).
>
> Yes, __ul_fallthrough seems better, and __attribute__((fallthrough))
> would be the best :-)
>
> It's strange if clang will use a different syntax for the same
> things. IMHO it would be better to ignore clang for this attribute.
Yes, Sami's last version just ignores clang. Seems that the different syntax
was for C++ only.
So branch 2017wk23 from git@github.com:kerolasa/lelux-utiliteetit.git is the
last version for merging.
> And I'm not sure if the change is compatible with coverity-scan where
> comment line /* fallthrough */ is required, but this not so important
> (coverity is maintained, so attribute will be supported one day...).
>
> Karel
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated
2017-06-08 19:52 ` [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated Sami Kerola
@ 2017-06-13 13:16 ` Karel Zak
2017-06-17 8:26 ` Sami Kerola
0 siblings, 1 reply; 31+ messages in thread
From: Karel Zak @ 2017-06-13 13:16 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Thu, Jun 08, 2017 at 08:52:09PM +0100, Sami Kerola wrote:
> The uuidgen has always had option to use time as a uuid value. To common
> users these timestamps have been difficult to convert to readable format, so
> add an option to do that.
The name of the tool is uuidgen and at first glance it seems like
--date is a way how to use a different time than the current ;-)
Maybe it would be better to create a small independent tool uuidparse
and print all available details about UUID (variant, type and time).
$ uuidparse 7e400110-3e4a-11e7-8af1-00037f500001
variant: DCE
type: time
time: 2017-05-21 17:25:32,471528+0000
$ uuidparse --time
2017-05-21 17:25:32,471528+0000
It would be also nice to accept more than one UUID on command line/stdin.
or so... Comments?
See libuuid/src/uuid_time.c where is test program.
> +static int print_uuid_date(char *date)
> +{
> + uuid_t uuid;
> + struct timeval tv;
> + char buf[ISO_8601_BUFSIZ];
> +
> + if (uuid_parse(date, uuid)) {
> + printf(_("invalid uuid: %s\n"), date);
"failed to parse UUID" sounds better
> + return 1;
> + }
Maybe you want to check UUID type and variant, only DCE time is
supported.
I think separated pull request would be better ;-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 13:03 ` Rüdiger Meier
@ 2017-06-13 13:41 ` Karel Zak
2017-06-13 14:52 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Karel Zak @ 2017-06-13 13:41 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: kerolasa, util-linux
On Tue, Jun 13, 2017 at 03:03:12PM +0200, Rüdiger Meier wrote:
>
>
> On 06/13/2017 02:51 PM, Karel Zak wrote:
> > On Tue, Jun 13, 2017 at 01:16:57AM +0200, Rüdiger Meier wrote:
> > > > > BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
> > > > > __ul_fallthrough
> > > > > like we have already __ul_calloc_size. IMO it would look more obvious to the
> > > > > reader.
> > > >
> > > > I don't have strong opinion about that, changed to one you proposed.
> > >
> > > Thanks, let's see whether Karel likes this attribute at all ;)
> >
> > Hmm...
> >
> > I don't like "meta-programming" where language keywords are
> > replaced by local macros, for example we have fallback (in c.h) for all
> > __attribute__ rather than define local macro for all attributes.
> >
> > __attribute__((fallthrough))
> >
> > should be fine on non-__GNUC__ as in this case __attribute__ is empty
> > macro (see c.h).
> >
> > Yes, __ul_fallthrough seems better, and __attribute__((fallthrough))
> > would be the best :-)
> >
> > It's strange if clang will use a different syntax for the same
> > things. IMHO it would be better to ignore clang for this attribute.
>
> Yes, Sami's last version just ignores clang. Seems that the different syntax
> was for C++ only.
>
> So branch 2017wk23 from git@github.com:kerolasa/lelux-utiliteetit.git is the
> last version for merging.
Cool, I see.
Now I read something about gcc and it seem it's able to recognize and
use comments, so __attribute__((fallthrough)) is unnecessary.
The default -Wimplicit-fallthrough setting is '3' and it means "parse
comments".
So, do we really need this patch? ;-)
https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
and man gcc man page:
-Wimplicit-fallthrough=0 disables the warning altogether.
-Wimplicit-fallthrough=1 matches .* regular expression, any comment is used as fallthrough comment.
-Wimplicit-fallthrough=2 case insensitively matches .*falls?[ \t-]*thr(ough|u).* regular expression.
-Wimplicit-fallthrough=3 case sensitively matches one of the following regular expressions:
-fallthrough
@fallthrough@
lint -fallthrough[ \t]*
[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*(Else,? |Intentional(ly)? )?
Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?
-Wimplicit-fallthrough=4 case sensitively matches one of the following regular expressions:
-fallthrough
@fallthrough@
lint -fallthrough[ \t]*
[ \t]*FALLTHR(OUGH|U)[ \t]*
-Wimplicit-fallthrough=5 doesn’t recognize any comments as fallthrough comments, only attributes disable the warning.
sounds all we need is to add -Wimplicit-fallthrough=3 to ./configure.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 13:41 ` Karel Zak
@ 2017-06-13 14:52 ` Rüdiger Meier
2017-06-13 20:00 ` Karel Zak
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-13 14:52 UTC (permalink / raw)
To: Karel Zak; +Cc: kerolasa, util-linux
On 06/13/2017 03:41 PM, Karel Zak wrote:
> On Tue, Jun 13, 2017 at 03:03:12PM +0200, Rüdiger Meier wrote:
>>
>>
>> On 06/13/2017 02:51 PM, Karel Zak wrote:
>>> On Tue, Jun 13, 2017 at 01:16:57AM +0200, Rüdiger Meier wrote:
>>>>>> BTW just for cosmetics. Maybe we should rename UL_FALLTHROUGH to
>>>>>> __ul_fallthrough
>>>>>> like we have already __ul_calloc_size. IMO it would look more obvious to the
>>>>>> reader.
>>>>>
>>>>> I don't have strong opinion about that, changed to one you proposed.
>>>>
>>>> Thanks, let's see whether Karel likes this attribute at all ;)
>>>
>>> Hmm...
>>>
>>> I don't like "meta-programming" where language keywords are
>>> replaced by local macros, for example we have fallback (in c.h) for all
>>> __attribute__ rather than define local macro for all attributes.
>>>
>>> __attribute__((fallthrough))
>>>
>>> should be fine on non-__GNUC__ as in this case __attribute__ is empty
>>> macro (see c.h).
>>>
>>> Yes, __ul_fallthrough seems better, and __attribute__((fallthrough))
>>> would be the best :-)
>>>
>>> It's strange if clang will use a different syntax for the same
>>> things. IMHO it would be better to ignore clang for this attribute.
>>
>> Yes, Sami's last version just ignores clang. Seems that the different syntax
>> was for C++ only.
>>
>> So branch 2017wk23 from git@github.com:kerolasa/lelux-utiliteetit.git is the
>> last version for merging.
>
> Cool, I see.
>
> Now I read something about gcc and it seem it's able to recognize and
> use comments, so __attribute__((fallthrough)) is unnecessary.
>
> The default -Wimplicit-fallthrough setting is '3' and it means "parse
> comments"
> So, do we really need this patch? ;-)
>
> https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
>
> and man gcc man page:
>
> -Wimplicit-fallthrough=0 disables the warning altogether.
> -Wimplicit-fallthrough=1 matches .* regular expression, any comment is used as fallthrough comment.
> -Wimplicit-fallthrough=2 case insensitively matches .*falls?[ \t-]*thr(ough|u).* regular expression.
> -Wimplicit-fallthrough=3 case sensitively matches one of the following regular expressions:
> -fallthrough
> @fallthrough@
> lint -fallthrough[ \t]*
> [ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
> FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?
> [ \t.!]*(Else,? |Intentional(ly)? )?
> Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?
> [ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
> fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?
> -Wimplicit-fallthrough=4 case sensitively matches one of the following regular expressions:
> -fallthrough
> @fallthrough@
> lint -fallthrough[ \t]*
> [ \t]*FALLTHR(OUGH|U)[ \t]*
> -Wimplicit-fallthrough=5 doesn’t recognize any comments as fallthrough comments, only attributes disable the warning.
>
> sounds all we need is to add -Wimplicit-fallthrough=3 to ./configur
No, -Wimplicit-fallthrough=3 is what we have already now by default.
Just tested. Without doing anything "/* fallthrough */" disables the
warning. But Sami fixed also other comments and places without comments.
So we could simply use "/* fallthrough */" everythere.
Note, -Wimplicit-fallthrough=2 would be even more relaxed, e.g.
/* Fallthrough because bla. */ would work too.
cu,
Rudi
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 14:52 ` Rüdiger Meier
@ 2017-06-13 20:00 ` Karel Zak
2017-06-13 20:11 ` Rüdiger Meier
0 siblings, 1 reply; 31+ messages in thread
From: Karel Zak @ 2017-06-13 20:00 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: kerolasa, util-linux
On Tue, Jun 13, 2017 at 04:52:20PM +0200, Rüdiger Meier wrote:
> > sounds all we need is to add -Wimplicit-fallthrough=3 to ./configur
> No, -Wimplicit-fallthrough=3 is what we have already now by default.
> Just tested. Without doing anything "/* fallthrough */" disables the
> warning. But Sami fixed also other comments and places without comments.
>
> So we could simply use "/* fallthrough */" everythere.
Yes, that's what I mean (don't use the macro at all).
Sami, can you update the patch and replace __ul_fallthrough with
/* fallthrough */ ?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 20:00 ` Karel Zak
@ 2017-06-13 20:11 ` Rüdiger Meier
2017-06-13 21:02 ` Karel Zak
0 siblings, 1 reply; 31+ messages in thread
From: Rüdiger Meier @ 2017-06-13 20:11 UTC (permalink / raw)
To: Karel Zak; +Cc: kerolasa, util-linux
On 06/13/2017 10:00 PM, Karel Zak wrote:
> On Tue, Jun 13, 2017 at 04:52:20PM +0200, Rüdiger Meier wrote:
>>> sounds all we need is to add -Wimplicit-fallthrough=3 to ./configur
>> No, -Wimplicit-fallthrough=3 is what we have already now by default.
>> Just tested. Without doing anything "/* fallthrough */" disables the
>> warning. But Sami fixed also other comments and places without comments.
>>
>> So we could simply use "/* fallthrough */" everythere.
>
> Yes, that's what I mean (don't use the macro at all).
>
> Sami, can you update the patch and replace __ul_fallthrough with
> /* fallthrough */ ?
>
> Karel
>
I've used one sed command on Sami's patch and submitted via github
https://github.com/karelzak/util-linux/pull/456
cu,
Rudi
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 20:11 ` Rüdiger Meier
@ 2017-06-13 21:02 ` Karel Zak
2017-06-17 8:23 ` Sami Kerola
0 siblings, 1 reply; 31+ messages in thread
From: Karel Zak @ 2017-06-13 21:02 UTC (permalink / raw)
To: Rüdiger Meier; +Cc: kerolasa, util-linux
On Tue, Jun 13, 2017 at 10:11:29PM +0200, Rüdiger Meier wrote:
> On 06/13/2017 10:00 PM, Karel Zak wrote:
> > On Tue, Jun 13, 2017 at 04:52:20PM +0200, Rüdiger Meier wrote:
> > > > sounds all we need is to add -Wimplicit-fallthrough=3 to ./configur
> > > No, -Wimplicit-fallthrough=3 is what we have already now by default.
> > > Just tested. Without doing anything "/* fallthrough */" disables the
> > > warning. But Sami fixed also other comments and places without comments.
> > >
> > > So we could simply use "/* fallthrough */" everythere.
> >
> > Yes, that's what I mean (don't use the macro at all).
> >
> > Sami, can you update the patch and replace __ul_fallthrough with
> > /* fallthrough */ ?
> >
> > Karel
> >
>
> I've used one sed command on Sami's patch and submitted via github
> https://github.com/karelzak/util-linux/pull/456
Applied, thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 00/11] pull: various small changes
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
` (10 preceding siblings ...)
2017-06-08 19:52 ` [PATCH 11/11] lib: remove _RLD_ from forbid environment variable list Sami Kerola
@ 2017-06-14 10:30 ` Karel Zak
11 siblings, 0 replies; 31+ messages in thread
From: Karel Zak @ 2017-06-14 10:30 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Thu, Jun 08, 2017 at 08:52:04PM +0100, Sami Kerola wrote:
> misc: fallthrough fixes
Fixed by patches from Rudi.
> line: do not print new line if nothing else was printed
> rename: notice when expression and replacement are the same string
> uuidgen: slice up the usage text
Applied.
> uuidgen: add --date option to display time when uuid was generated
Not applied, "uuidparse" suggested.
> isosize: avoid reading more data than what is needed
> misc: fix reassigned values before old ones has been used [cppcheck]
> losetup: add missing initializer [clang]
> misc: remove stray semicolons
> lib: simplify cpuset if clauses that return
> lib: remove _RLD_ from forbid environment variable list
Applied, thanks.
Please, don't add new features to cleanup pull requests, and always
use separate pull request for stuff you're not sure with it :)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/11] misc: fallthrough fixes
2017-06-13 21:02 ` Karel Zak
@ 2017-06-17 8:23 ` Sami Kerola
0 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-17 8:23 UTC (permalink / raw)
To: Karel Zak; +Cc: Rüdiger Meier, util-linux
On 13 June 2017 at 22:02, Karel Zak <kzak@redhat.com> wrote:
>> I've used one sed command on Sami's patch and submitted via github
>> https://github.com/karelzak/util-linux/pull/456
>
> Applied, thanks!
Thank you Rudi & Karel pushing this pull request over finishing line.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated
2017-06-13 13:16 ` Karel Zak
@ 2017-06-17 8:26 ` Sami Kerola
0 siblings, 0 replies; 31+ messages in thread
From: Sami Kerola @ 2017-06-17 8:26 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 13 June 2017 at 14:16, Karel Zak <kzak@redhat.com> wrote:
> On Thu, Jun 08, 2017 at 08:52:09PM +0100, Sami Kerola wrote:
>> The uuidgen has always had option to use time as a uuid value. To common
>> users these timestamps have been difficult to convert to readable format, so
>> add an option to do that.
>
> The name of the tool is uuidgen and at first glance it seems like
> --date is a way how to use a different time than the current ;-)
>
> Maybe it would be better to create a small independent tool uuidparse
> and print all available details about UUID (variant, type and time).
>
> $ uuidparse 7e400110-3e4a-11e7-8af1-00037f500001
> variant: DCE
> type: time
> time: 2017-05-21 17:25:32,471528+0000
>
> $ uuidparse --time
> 2017-05-21 17:25:32,471528+0000
>
> It would be also nice to accept more than one UUID on command line/stdin.
>
> or so... Comments?
>
> See libuuid/src/uuid_time.c where is test program.
>
>> +static int print_uuid_date(char *date)
>> +{
>> + uuid_t uuid;
>> + struct timeval tv;
>> + char buf[ISO_8601_BUFSIZ];
>> +
>> + if (uuid_parse(date, uuid)) {
>> + printf(_("invalid uuid: %s\n"), date);
>
> "failed to parse UUID" sounds better
>
>> + return 1;
>> + }
>
> Maybe you want to check UUID type and variant, only DCE time is
> supported.
>
> I think separated pull request would be better ;-)
I thought it would be better avoid adding small binaries, but
no problems I can do that and ensure all the other feedback
is incorporated to that utility as well.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2017-06-17 8:26 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-08 19:52 [PATCH 00/11] pull: various small changes Sami Kerola
2017-06-08 19:52 ` [PATCH 01/11] misc: fallthrough fixes Sami Kerola
2017-06-09 11:14 ` Ruediger Meier
2017-06-09 21:10 ` Rüdiger Meier
2017-06-11 8:36 ` Sami Kerola
2017-06-12 8:40 ` Rüdiger Meier
2017-06-12 21:54 ` Sami Kerola
2017-06-12 23:16 ` Rüdiger Meier
2017-06-13 12:51 ` Karel Zak
2017-06-13 13:03 ` Rüdiger Meier
2017-06-13 13:41 ` Karel Zak
2017-06-13 14:52 ` Rüdiger Meier
2017-06-13 20:00 ` Karel Zak
2017-06-13 20:11 ` Rüdiger Meier
2017-06-13 21:02 ` Karel Zak
2017-06-17 8:23 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 02/11] line: do not print new line if nothing else was printed Sami Kerola
2017-06-09 12:01 ` Ruediger Meier
2017-06-11 8:19 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 03/11] rename: notice when expression and replacement are the same string Sami Kerola
2017-06-08 19:52 ` [PATCH 04/11] uuidgen: slice up the usage text Sami Kerola
2017-06-08 19:52 ` [PATCH 05/11] uuidgen: add --date option to display time when uuid was generated Sami Kerola
2017-06-13 13:16 ` Karel Zak
2017-06-17 8:26 ` Sami Kerola
2017-06-08 19:52 ` [PATCH 06/11] isosize: avoid reading more data than what is needed Sami Kerola
2017-06-08 19:52 ` [PATCH 07/11] misc: fix reassigned values before old ones has been used [cppcheck] Sami Kerola
2017-06-08 19:52 ` [PATCH 08/11] losetup: add missing initializer [clang] Sami Kerola
2017-06-08 19:52 ` [PATCH 09/11] misc: remove stray semicolons Sami Kerola
2017-06-08 19:52 ` [PATCH 10/11] lib: simplify cpuset if clauses that return Sami Kerola
2017-06-08 19:52 ` [PATCH 11/11] lib: remove _RLD_ from forbid environment variable list Sami Kerola
2017-06-14 10:30 ` [PATCH 00/11] pull: various small changes Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).