mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
Shell: Don't require ArgsParser values to be null-terminated
This commit is contained in:
parent
1280d70d74
commit
1173adb90a
1 changed files with 14 additions and 8 deletions
|
@ -1314,6 +1314,10 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
|
|
||||||
Vector<StringView> descriptors;
|
Vector<StringView> descriptors;
|
||||||
Variant<Core::ArgsParser::Option, Core::ArgsParser::Arg, Empty> current;
|
Variant<Core::ArgsParser::Option, Core::ArgsParser::Arg, Empty> current;
|
||||||
|
DeprecatedString help_string_storage;
|
||||||
|
DeprecatedString long_name_storage;
|
||||||
|
DeprecatedString value_name_storage;
|
||||||
|
DeprecatedString name_storage;
|
||||||
DeprecatedString current_variable;
|
DeprecatedString current_variable;
|
||||||
// if max > 1 or min < 1, or explicit `--list`.
|
// if max > 1 or min < 1, or explicit `--list`.
|
||||||
bool treat_arg_as_list = false;
|
bool treat_arg_as_list = false;
|
||||||
|
@ -1521,6 +1525,7 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.add_option(Core::ArgsParser::Option {
|
parser.add_option(Core::ArgsParser::Option {
|
||||||
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
.help_string = "Set the help string of the option or argument being defined",
|
.help_string = "Set the help string of the option or argument being defined",
|
||||||
|
@ -1533,8 +1538,8 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
[&](auto& option) {
|
[&](auto& option) {
|
||||||
VERIFY(value.length() == strlen(value.characters_without_null_termination()));
|
help_string_storage = value;
|
||||||
option.help_string = value.characters_without_null_termination();
|
option.help_string = help_string_storage.characters();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1554,8 +1559,9 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
warnln("Repeated application of --long-name is not allowed, current option has long name set to \"{}\"", option->long_name);
|
warnln("Repeated application of --long-name is not allowed, current option has long name set to \"{}\"", option->long_name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
VERIFY(value.length() == strlen(value.characters_without_null_termination()));
|
|
||||||
option->long_name = value.characters_without_null_termination();
|
long_name_storage = value;
|
||||||
|
option->long_name = long_name_storage.characters();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1603,8 +1609,8 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VERIFY(value.length() == strlen(value.characters_without_null_termination()));
|
value_name_storage = value;
|
||||||
option.value_name = value.characters_without_null_termination();
|
option.value_name = value_name_storage.characters();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](Core::ArgsParser::Arg& arg) {
|
[&](Core::ArgsParser::Arg& arg) {
|
||||||
|
@ -1613,8 +1619,8 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VERIFY(value.length() == strlen(value.characters_without_null_termination()));
|
name_storage = value;
|
||||||
arg.name = value.characters_without_null_termination();
|
arg.name = name_storage.characters();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue