Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some issues found by static analyzers #2634

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ static int getargs(int argc, char **argv)
char *search_value;
bool found_value = false;
char *cmdline = NULL;
char *cmdline_iter = NULL;
Copy link
Contributor

@dtardon dtardon Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this into the preceding line?


char *p = getenv("CMDLINE");
if (p == NULL) {
usage(GETARGS, EXIT_FAILURE, "CMDLINE env not set");
}
cmdline = strdup(p);

if (argc != 2) {
if (argc != 2)
usage(GETARGS, EXIT_FAILURE, "Number of arguments invalid");
}

search_key = argv[1];

Expand All @@ -277,9 +276,16 @@ static int getargs(int argc, char **argv)
if (strlen(search_key) == 0)
usage(GETARGS, EXIT_FAILURE, "search key undefined");

cmdline = strdup(p);
if (cmdline == NULL) {
fprintf(stderr, "ERROR: out of memory.\n");
exit(EXIT_FAILURE);
}
cmdline_iter = cmdline;

do {
char *key = NULL, *value = NULL;
cmdline = next_arg(cmdline, &key, &value);
cmdline = next_arg(cmdline_iter, &key, &value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmdline_iter = ...

if (strcmp(key, search_key) == 0) {
if (search_value) {
if (strcmp(value, search_value) == 0) {
Expand All @@ -295,7 +301,10 @@ static int getargs(int argc, char **argv)
found_value = true;
}
}
} while (cmdline[0]);
} while (cmdline_iter[0]);

free(cmdline_iter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free(cmdline)


return found_value ? EXIT_SUCCESS : EXIT_FAILURE;
}

Expand Down