From f718b35b1bd9079fafd1f56f66da3e8d2641c5ce Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 23 Feb 2018 13:45:45 +0200 Subject: [PATCH] shared/shell: Fix not handling sort options getopt_long index is only valid for long options. --- src/shared/shell.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 1fec58d17..3aabda7bf 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -787,7 +787,7 @@ static void usage(int argc, char **argv, const struct bt_shell_opt *opt) void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt) { - int c, index = 0; + int c, index = -1; struct option options[256]; char optstr[256]; size_t offset; @@ -817,6 +817,13 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt) data.timeout = atoi(optarg); break; default: + if (index < 0) { + for (index = 0; options[index].val; index++) { + if (c == options[index].val) + break; + } + } + if (c != opt->options[index - offset].val) { usage(argc, argv, opt); exit(EXIT_SUCCESS); -- 2.47.3