mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
profile: Prevent crash when -p is supplied a non-integer value
Instead of crashing we give a helpful warning message to the user. This also removes a fixme! :^)
This commit is contained in:
parent
6811ab9c3b
commit
5563ebab5a
Notes:
sideshowbarker
2024-07-17 11:33:34 +09:00
Author: https://github.com/PrestonLTaylor Commit: https://github.com/SerenityOS/serenity/commit/5563ebab5a Pull-request: https://github.com/SerenityOS/serenity/pull/18616
1 changed files with 18 additions and 2 deletions
|
@ -11,6 +11,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static Optional<pid_t> determine_pid_to_profile(StringView pid_argument, bool all_processes);
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -86,9 +88,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// FIXME: Handle error case.
|
||||
pid_t pid = all_processes ? -1 : pid_argument.to_int().release_value();
|
||||
auto pid_opt = determine_pid_to_profile(pid_argument, all_processes);
|
||||
if (!pid_opt.has_value()) {
|
||||
warnln("-p <PID> requires an integer value.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid_t pid = pid_opt.value();
|
||||
if (wait || enable) {
|
||||
TRY(Core::System::profiling_enable(pid, event_mask));
|
||||
|
||||
|
@ -116,3 +122,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Optional<pid_t> determine_pid_to_profile(StringView pid_argument, bool all_processes)
|
||||
{
|
||||
if (all_processes) {
|
||||
return { -1 };
|
||||
}
|
||||
|
||||
// pid_argument is guaranteed to have a value
|
||||
return pid_argument.to_int();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue