Skip to content

Commit

Permalink
Fix command argument parser
Browse files Browse the repository at this point in the history
Fixes segmentation fault on unknown arguments;

Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Dec 28, 2023
1 parent 9e3d2f6 commit b964440
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,14 @@ static enum config_status load_config(const char* key, const char* value)
}

// set new scheme
block->scheme = realloc(block->scheme, scheme_sz * sizeof(enum info_field));
memcpy(block->scheme, scheme, scheme_sz * sizeof(enum info_field));
if (scheme_sz) {
block->scheme =
realloc(block->scheme, scheme_sz * sizeof(enum info_field));
memcpy(block->scheme, scheme, scheme_sz * sizeof(enum info_field));
} else {
free(block->scheme);
block->scheme = NULL;
}
block->scheme_sz = scheme_sz;

return cfgst_ok;
Expand Down
7 changes: 6 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ static int parse_cmdargs(int argc, char* argv[])

// parse arguments
while ((opt = getopt_long(argc, argv, short_opts, options, NULL)) != -1) {
const struct cmdarg* arg = arguments;
const struct cmdarg* arg;
if (opt == '?') {
return -1;
}
// get argument description
arg = arguments;
while (arg->short_opt != opt) {
++arg;
}
Expand Down

0 comments on commit b964440

Please sign in to comment.