From 6d97b623cdfed59bd8a747ee492cca5512966dc8 Mon Sep 17 00:00:00 2001 From: Sahan Fernando Date: Tue, 12 Jan 2021 00:38:09 +1100 Subject: [PATCH] Everywhere: Fix incorrect uses of String::format and StringBuilder::appendf These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect. --- Libraries/LibDiff/Format.cpp | 2 +- Libraries/LibGfx/Triangle.cpp | 2 +- Services/DHCPClient/DHCPv4.h | 2 +- Services/SystemServer/main.cpp | 4 ++-- Services/TelnetServer/Command.h | 2 +- Services/WebServer/Client.cpp | 2 +- Userland/gunzip.cpp | 2 +- Userland/w.cpp | 2 +- Userland/watch.cpp | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Libraries/LibDiff/Format.cpp b/Libraries/LibDiff/Format.cpp index b6ee7d172b..38766b89cb 100644 --- a/Libraries/LibDiff/Format.cpp +++ b/Libraries/LibDiff/Format.cpp @@ -34,7 +34,7 @@ String generate_only_additions(const String& text) { auto lines = text.split('\n', true); // Keep empty StringBuilder builder; - builder.appendf("@@ -1,%zu +1,%zu @@\n", lines.size()); + builder.appendf("@@ -0,0 +1,%zu @@\n", lines.size()); for (const auto& line : lines) { builder.appendf("+%s\n", line.characters()); } diff --git a/Libraries/LibGfx/Triangle.cpp b/Libraries/LibGfx/Triangle.cpp index f5fcab2047..d326b59f1c 100644 --- a/Libraries/LibGfx/Triangle.cpp +++ b/Libraries/LibGfx/Triangle.cpp @@ -31,7 +31,7 @@ namespace Gfx { String Triangle::to_string() const { - return String::format("({},{},{})", m_a, m_b, m_c); + return String::formatted("({},{},{})", m_a, m_b, m_c); } const LogStream& operator<<(const LogStream& stream, const Triangle& value) diff --git a/Services/DHCPClient/DHCPv4.h b/Services/DHCPClient/DHCPv4.h index 68bfd36171..a773167683 100644 --- a/Services/DHCPClient/DHCPv4.h +++ b/Services/DHCPClient/DHCPv4.h @@ -173,7 +173,7 @@ struct ParsedDHCPv4Options { { StringBuilder builder; builder.append("DHCP Options ("); - builder.appendf("%d", options.size()); + builder.appendf("%zu", options.size()); builder.append(" entries)\n"); for (auto& opt : options) { builder.appendf("\toption %d (%d bytes):", (u8)opt.key, (u8)opt.value.length); diff --git a/Services/SystemServer/main.cpp b/Services/SystemServer/main.cpp index f243032b95..6409b0eda6 100644 --- a/Services/SystemServer/main.cpp +++ b/Services/SystemServer/main.cpp @@ -130,7 +130,7 @@ static void prepare_devfs() for (size_t index = 0; index < 4; index++) { // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown(String::format("/dev/tty%d", index).characters(), 0, 2); + rc = chown(String::formatted("/dev/tty{}", index).characters(), 0, 2); if (rc < 0) { ASSERT_NOT_REACHED(); } @@ -138,7 +138,7 @@ static void prepare_devfs() for (size_t index = 0; index < 4; index++) { // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown(String::format("/dev/ttyS%d", index).characters(), 0, 2); + rc = chown(String::formatted("/dev/ttyS{}", index).characters(), 0, 2); if (rc < 0) { ASSERT_NOT_REACHED(); } diff --git a/Services/TelnetServer/Command.h b/Services/TelnetServer/Command.h index ac696c2111..25afb1fe22 100644 --- a/Services/TelnetServer/Command.h +++ b/Services/TelnetServer/Command.h @@ -73,7 +73,7 @@ struct Command { builder.append("SUPPRESS_GO_AHEAD"); break; default: - builder.append(String::format("UNKNOWN<%02x>")); + builder.append(String::format("UNKNOWN<%02x>", subcommand)); break; } diff --git a/Services/WebServer/Client.cpp b/Services/WebServer/Client.cpp index 84ba323d64..c3840bd118 100644 --- a/Services/WebServer/Client.cpp +++ b/Services/WebServer/Client.cpp @@ -227,7 +227,7 @@ void Client::handle_directory_listing(const String& requested_path, const String builder.append(escape_html_entities(name)); builder.append(" "); - builder.appendf("%10d ", st.st_size); + builder.appendf("%10zd ", st.st_size); builder.append(""); builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string()); builder.append(""); diff --git a/Userland/gunzip.cpp b/Userland/gunzip.cpp index cf0d473850..58678d1b88 100644 --- a/Userland/gunzip.cpp +++ b/Userland/gunzip.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) for (String filename : filenames) { if (!filename.ends_with(".gz")) - filename = String::format("%s.gz", filename); + filename = String::format("%s.gz", filename.characters()); const auto input_filename = filename; const auto output_filename = filename.substring_view(0, filename.length() - 3); diff --git a/Userland/w.cpp b/Userland/w.cpp index 7e38137276..4c9dbc106b 100644 --- a/Userland/w.cpp +++ b/Userland/w.cpp @@ -107,7 +107,7 @@ int main() if (stat(tty.characters(), &st) == 0) { auto idle_time = now - st.st_mtime; if (idle_time >= 0) { - builder.appendf("%ds", idle_time); + builder.appendf("%llds", idle_time); idle_string = builder.to_string(); } } diff --git a/Userland/watch.cpp b/Userland/watch.cpp index 5188685e08..1377a7667c 100644 --- a/Userland/watch.cpp +++ b/Userland/watch.cpp @@ -45,7 +45,7 @@ static volatile pid_t child_pid = -1; static String build_header_string(const Vector& command, const struct timeval& interval) { StringBuilder builder; - builder.appendf("Every %d", interval.tv_sec); + builder.appendff("Every {}", interval.tv_sec); builder.appendf(".%ds: \x1b[1m", interval.tv_usec / 100000); builder.join(' ', command); builder.append("\x1b[0m");