-
Notifications
You must be signed in to change notification settings - Fork 401
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,12 +180,12 @@ static int getarg(int argc, char **argv) | |
char *end_value = NULL; | ||
bool bool_value = false; | ||
char *cmdline = NULL; | ||
char *cmdline_iter = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge this into the preceding line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the var doesn't have to be initialized. |
||
|
||
char *p = getenv("CMDLINE"); | ||
if (p == NULL) { | ||
usage(GETARG, EXIT_FAILURE, "CMDLINE env not set"); | ||
} | ||
cmdline = strdup(p); | ||
|
||
if (argc != 2) { | ||
usage(GETARG, EXIT_FAILURE, "Number of arguments invalid"); | ||
|
@@ -204,9 +204,16 @@ static int getarg(int argc, char **argv) | |
if (strlen(search_key) == 0) | ||
usage(GETARG, EXIT_FAILURE, "search key undefined"); | ||
|
||
cmdline = strdup(p); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I see no reason to copy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have... |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (strcmp(key, search_key) == 0) { | ||
if (value) { | ||
end_value = value; | ||
|
@@ -216,7 +223,9 @@ static int getarg(int argc, char **argv) | |
bool_value = true; | ||
} | ||
} | ||
} while (cmdline[0]); | ||
} while (cmdline_iter[0]); | ||
|
||
free(cmdline); | ||
|
||
if (search_value) { | ||
if (end_value && strcmp(end_value, search_value) == 0) { | ||
|
@@ -244,16 +253,15 @@ static int getargs(int argc, char **argv) | |
char *search_value; | ||
bool found_value = false; | ||
char *cmdline = NULL; | ||
char *cmdline_iter = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
|
||
|
@@ -268,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (strcmp(key, search_key) == 0) { | ||
if (search_value) { | ||
if (strcmp(value, search_value) == 0) { | ||
|
@@ -286,7 +301,10 @@ static int getargs(int argc, char **argv) | |
found_value = true; | ||
} | ||
} | ||
} while (cmdline[0]); | ||
} while (cmdline_iter[0]); | ||
|
||
free(cmdline_iter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return found_value ? EXIT_SUCCESS : EXIT_FAILURE; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the fix, but maybe add a check that
strv_split()
succeeded?