mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:57:47 +00:00
LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in StringViews and might have a non-properly-null-terminated string as a value. As a bonus, using StringView (and DeprecatedString where necessary) leads to nicer looking code too :^)
This commit is contained in:
parent
60908adcbe
commit
500044906d
43 changed files with 122 additions and 145 deletions
|
@ -18,7 +18,7 @@ int main(int argc, char** argv)
|
|||
for (auto i = 0; i < argc; ++i)
|
||||
arguments.append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
char const* target = nullptr;
|
||||
DeprecatedString target;
|
||||
int max_file_size = 1024 * 1024;
|
||||
int count = 1024;
|
||||
|
||||
|
@ -28,7 +28,7 @@ int main(int argc, char** argv)
|
|||
args_parser.add_positional_argument(target, "Target file path", "target");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
int fd = creat(target, 0666);
|
||||
int fd = creat(target.characters(), 0666);
|
||||
if (fd < 0) {
|
||||
perror("Couldn't create target file");
|
||||
return EXIT_FAILURE;
|
||||
|
@ -38,13 +38,13 @@ int main(int argc, char** argv)
|
|||
for (int i = 0; i < count; i++) {
|
||||
auto new_file_size = AK::get_random<uint64_t>() % (max_file_size + 1);
|
||||
printf("(%d/%d)\tTruncating to %" PRIu64 " bytes...\n", i + 1, count, new_file_size);
|
||||
if (truncate(target, new_file_size) < 0) {
|
||||
if (truncate(target.characters(), new_file_size) < 0) {
|
||||
perror("Couldn't truncate target file");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (unlink(target) < 0) {
|
||||
if (unlink(target.characters()) < 0) {
|
||||
perror("Couldn't remove target file");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char** argv)
|
|||
for (auto i = 0; i < argc; ++i)
|
||||
arguments.append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
char const* target = nullptr;
|
||||
DeprecatedString target;
|
||||
int min_block_offset = 0;
|
||||
int block_length = 2048;
|
||||
int block_size = 512;
|
||||
|
@ -96,7 +96,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
auto buffer = buffer_result.release_value();
|
||||
|
||||
int fd = open(target, O_CREAT | O_RDWR, 0666);
|
||||
int fd = open(target.characters(), O_CREAT | O_RDWR, 0666);
|
||||
if (fd < 0) {
|
||||
perror("Couldn't create target file");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -305,7 +305,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringView per_file_location;
|
||||
StringView pass_through_parameters;
|
||||
StringView runner_command = "test262-runner"sv;
|
||||
char const* test_directory = nullptr;
|
||||
StringView test_directory;
|
||||
bool dont_print_progress = false;
|
||||
bool dont_disable_core_dump = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue