From 500044906d1b90f1c8b1a2f5675a2f82ab92b758 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Wed, 1 Mar 2023 00:11:43 +0330 Subject: 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 :^) --- Tests/Kernel/stress-truncate.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Tests/Kernel/stress-truncate.cpp') diff --git a/Tests/Kernel/stress-truncate.cpp b/Tests/Kernel/stress-truncate.cpp index 684a697124..1e066155c5 100644 --- a/Tests/Kernel/stress-truncate.cpp +++ b/Tests/Kernel/stress-truncate.cpp @@ -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() % (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; } -- cgit v1.2.3