Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 3af590a

Browse files
committed
fix(cli): Append zeros in CLI option array
the 4th argument of `getopt_long()` is an array of `struct option`. And this array should be ended with a `struct option` filled with zeros. Fixes #436
1 parent df53b0b commit 3af590a

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

accelerator/cli_info.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static struct ta_cli_argument_s {
7272
{"cache", CACHE, "Enable cache server with Y", REQUIRED_ARG},
7373
{"config", CONF_CLI, "Read configuration file", REQUIRED_ARG},
7474
{"proxy_passthrough", PROXY_API, "Pass proxy API directly to IRI without processing", NO_ARG},
75-
{"verbose", VERBOSE, "Enable logger", NO_ARG}};
75+
{"verbose", VERBOSE, "Enable logger", NO_ARG},
76+
{NULL, 0, NULL, (ta_cli_arg_requirement_t)0}};
7677

7778
static const int cli_cmd_num = sizeof(ta_cli_arguments_g) / sizeof(struct ta_cli_argument_s);
7879

accelerator/config.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#define CONFIG_LOGGER "config"
1414

1515
static logger_id_t logger_id;
16-
// FIXME: We need further improvements without depending on temporary variables
17-
static int tmp_argc;
1816

1917
int get_conf_key(char const* const key) {
2018
for (int i = 0; i < cli_cmd_num; ++i) {
@@ -26,19 +24,6 @@ int get_conf_key(char const* const key) {
2624
return 0;
2725
}
2826

29-
static void remove_nonvalue_dash(int argc, char** argv) {
30-
for (int i = 1; i < argc; i++) {
31-
if ((strlen(argv[i]) == 2) && (!strncmp(argv[i], "--", 2))) {
32-
argc--;
33-
if (argc == (i + 1)) {
34-
break;
35-
}
36-
memmove(argv + i, argv + (i + 1), (argc - i) * sizeof(char*));
37-
}
38-
}
39-
tmp_argc = argc;
40-
}
41-
4227
struct option* cli_build_options() {
4328
struct option* long_options = (struct option*)malloc(cli_cmd_num * sizeof(struct option));
4429
for (int i = 0; i < cli_cmd_num; ++i) {
@@ -205,9 +190,6 @@ status_t ta_core_file_init(ta_core_t* const core, int argc, char** argv) {
205190
goto done;
206191
}
207192

208-
// remove `--` from argv
209-
remove_nonvalue_dash(argc, argv);
210-
211193
// Loop through the CLI arguments for first time to find the configuration file path
212194
while ((key = getopt_long(argc, argv, "hv", long_options, NULL)) != -1) {
213195
switch (key) {
@@ -295,10 +277,7 @@ status_t ta_core_cli_init(ta_core_t* const core, int argc, char** argv) {
295277
status_t ret = SC_OK;
296278
struct option* long_options = cli_build_options();
297279

298-
// remove `--` from argv
299-
remove_nonvalue_dash(tmp_argc, argv);
300-
301-
while ((key = getopt_long(tmp_argc, argv, "hv", long_options, NULL)) != -1) {
280+
while ((key = getopt_long(argc, argv, "hv", long_options, NULL)) != -1) {
302281
switch (key) {
303282
case ':':
304283
ret = SC_CONF_MISSING_ARGUMENT;

0 commit comments

Comments
 (0)