1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:58:12 +00:00

Everywhere: Explicitly specify the size in StringView constructors

This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
This commit is contained in:
sin-ack 2022-07-11 19:53:29 +00:00 committed by Andreas Kling
parent e3da0adfe6
commit c70f45ff44
75 changed files with 264 additions and 203 deletions

View file

@ -17,7 +17,7 @@
using namespace Help;
static String parse_input(char const* input)
static String parse_input(StringView input)
{
AK::URL url(input);
if (url.is_valid())
@ -50,9 +50,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
.name = "section",
.min_values = 0,
.max_values = 1,
.accept_value = [&](char const* input) {
.accept_value = [&](char const* input_ptr) {
StringView input { input_ptr, strlen(input_ptr) };
// If it's a number, use it as the section
if (auto number = StringView(input).to_int(); number.has_value()) {
if (auto number = input.to_int(); number.has_value()) {
section = number.value();
return true;
}
@ -66,7 +67,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
.name = "page",
.min_values = 0,
.max_values = 1,
.accept_value = [&](char const* input) {
.accept_value = [&](char const* input_ptr) {
StringView input { input_ptr, strlen(input_ptr) };
// If start_page was already set by our section arg, then it can't be set again
if (start_page.is_empty())
return false;