From 6fe37cb471b46dda7c222fc798a566aaca2475d0 Mon Sep 17 00:00:00 2001 From: Avery Date: Wed, 2 Sep 2020 22:35:19 -0600 Subject: [PATCH] Userland/tt: Use a default value for the test to run Addresses #3394 which was caused by dereferencing null `test_name` when no arguments were given to /bin/tt. Additionally, arguments other than the defined tests now print usage and exit to avoid running the default test. --- Userland/tt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/tt.cpp b/Userland/tt.cpp index 184122b6f4..3e7b3ccd71 100644 --- a/Userland/tt.cpp +++ b/Userland/tt.cpp @@ -41,7 +41,7 @@ static int set_stack_test(); int main(int argc, char** argv) { - const char* test_name = nullptr; + const char* test_name = "n"; Core::ArgsParser args_parser; args_parser.add_positional_argument(test_name, "Test to run (m = mutex, d = detached, p = priority, s = stack size, t = simple thread test, x = set stack, nothing = join race)", "test-name", Core::ArgsParser::Required::No); @@ -59,6 +59,10 @@ int main(int argc, char** argv) return staying_alive_test(); if (*test_name == 'x') return set_stack_test(); + if (*test_name != 'n') { + args_parser.print_usage(stdout, argv[0]); + return 1; + } printf("Hello from the first thread!\n"); pthread_t thread_id;