Fix passing invalid value to pause-method argument not causing an error

This commit is contained in:
Konstantin Pereiaslov
2024-01-01 17:50:54 -06:00
parent a983cb2490
commit 7b0294558c
2 changed files with 8 additions and 6 deletions

View File

@@ -108,22 +108,23 @@ char *parse_command_line_arguments(int argc, char *argv[]) {
break; break;
case 'm': case 'm':
char *method = strdup(optarg); char *method = strdup(optarg);
for (int i = 0; i<sizeof(method); i++) { for (int i = 0; i < sizeof(method); i++) {
method[i] = toupper(method[i]); method[i] = toupper(method[i]);
} }
for (int i = 1; pause_method_string[i] != NULL; i++) { pause_method = PAUSE_METHOD_UNKNOWN;
for (int i = 1; pause_method_string[i] != NULL; i++) {
if (strcmp(pause_method_string[i], method) == 0) { if (strcmp(pause_method_string[i], method) == 0) {
pause_method = i; pause_method = i;
break; break;
} }
} }
if (!pause_method) { if (pause_method == PAUSE_METHOD_UNKNOWN) {
fprintf_error("Invalid value for --pause-method|m argument: \"%s\". Supported values: ", optarg); fprintf_error("Invalid value for --pause-method|m argument: \"%s\". Supported values: ", optarg);
for (int i=1; pause_method_string[i] != NULL; i++) { for (int i = 1; pause_method_string[i] != NULL; i++) {
fprintf_error(pause_method_string[i]); fprintf_error(pause_method_string[i]);
if (pause_method_string[i+1] != NULL) { if (pause_method_string[i + 1] != NULL) {
fprintf_error(", "); fprintf_error(", ");
} }
} }
fprintf_error("\n"); fprintf_error("\n");
exit(1); exit(1);

View File

@@ -6,6 +6,7 @@
#define RUNWHENIDLE_PAUSE_METHODS_H #define RUNWHENIDLE_PAUSE_METHODS_H
enum pause_method { enum pause_method {
PAUSE_METHOD_UNKNOWN = 0,
//order must match order in pause_method_string //order must match order in pause_method_string
PAUSE_METHOD_SIGTSTP = 1, PAUSE_METHOD_SIGTSTP = 1,
PAUSE_METHOD_SIGSTOP = 2, PAUSE_METHOD_SIGSTOP = 2,