summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSahan Fernando <sahan.h.fernando@gmail.com>2021-01-12 01:01:33 +1100
committerAndreas Kling <kling@serenityos.org>2021-01-11 21:06:32 +0100
commitfe2b8906d47ce2ca95dcd7d374022c43a3e57197 (patch)
tree5ab9e2de76c1239de61b7f2cb0b6e1a1b3e3ca36
parent6d97b623cdfed59bd8a747ee492cca5512966dc8 (diff)
downloadserenity-fe2b8906d47ce2ca95dcd7d374022c43a3e57197.zip
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.
-rw-r--r--Libraries/LibLine/Editor.cpp4
-rw-r--r--Libraries/LibLine/XtermSuggestionDisplay.cpp2
-rw-r--r--Libraries/LibMarkdown/Heading.cpp4
-rw-r--r--Libraries/LibMarkdown/Table.cpp9
-rw-r--r--Libraries/LibRegex/RegexByteCode.cpp6
-rw-r--r--Libraries/LibRegex/RegexByteCode.h12
-rw-r--r--Libraries/LibWeb/Loader/FrameLoader.cpp5
7 files changed, 21 insertions, 21 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index d0358f16fe..7ed04b93c4 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -1356,7 +1356,7 @@ String Style::to_string() const
if (m_foreground.m_is_rgb) {
builder.join(", ", m_foreground.m_rgb_color);
} else {
- builder.appendf("(XtermColor) %d", m_foreground.m_xterm_color);
+ builder.appendf("(XtermColor) %d", (int)m_foreground.m_xterm_color);
}
builder.append("), ");
}
@@ -1366,7 +1366,7 @@ String Style::to_string() const
if (m_background.m_is_rgb) {
builder.join(' ', m_background.m_rgb_color);
} else {
- builder.appendf("(XtermColor) %d", m_background.m_xterm_color);
+ builder.appendf("(XtermColor) %d", (int)m_background.m_xterm_color);
}
builder.append("), ");
}
diff --git a/Libraries/LibLine/XtermSuggestionDisplay.cpp b/Libraries/LibLine/XtermSuggestionDisplay.cpp
index fac5bc732c..7e341854ee 100644
--- a/Libraries/LibLine/XtermSuggestionDisplay.cpp
+++ b/Libraries/LibLine/XtermSuggestionDisplay.cpp
@@ -153,7 +153,7 @@ void XtermSuggestionDisplay::display(const SuggestionManager& manager)
if (m_pages.size() > 1) {
auto left_arrow = page_index > 0 ? '<' : ' ';
auto right_arrow = page_index < m_pages.size() - 1 ? '>' : ' ';
- auto string = String::format("%c page %d of %d %c", left_arrow, page_index + 1, m_pages.size(), right_arrow);
+ auto string = String::format("%c page %zu of %zu %c", left_arrow, page_index + 1, m_pages.size(), right_arrow);
if (string.length() > m_num_columns - 1) {
// This would overflow into the next line, so just don't print an indicator.
diff --git a/Libraries/LibMarkdown/Heading.cpp b/Libraries/LibMarkdown/Heading.cpp
index 8bee287bfe..a29686ef03 100644
--- a/Libraries/LibMarkdown/Heading.cpp
+++ b/Libraries/LibMarkdown/Heading.cpp
@@ -32,9 +32,9 @@ namespace Markdown {
String Heading::render_to_html() const
{
StringBuilder builder;
- builder.appendf("<h%d>", m_level);
+ builder.appendf("<h%zu>", m_level);
builder.append(m_text.render_to_html());
- builder.appendf("</h%d>\n", m_level);
+ builder.appendf("</h%zu>\n", m_level);
return builder.build();
}
diff --git a/Libraries/LibMarkdown/Table.cpp b/Libraries/LibMarkdown/Table.cpp
index 60fe6e56c5..9298a37e94 100644
--- a/Libraries/LibMarkdown/Table.cpp
+++ b/Libraries/LibMarkdown/Table.cpp
@@ -32,7 +32,6 @@ namespace Markdown {
String Table::render_for_terminal(size_t view_width) const
{
auto unit_width_length = view_width == 0 ? 4 : ((float)(view_width - m_columns.size()) / (float)m_total_width);
- StringBuilder format_builder;
StringBuilder builder;
auto write_aligned = [&](const auto& text, auto width, auto alignment) {
@@ -40,17 +39,13 @@ String Table::render_for_terminal(size_t view_width) const
for (auto& span : text.spans())
original_length += span.text.length();
auto string = text.render_for_terminal();
- format_builder.clear();
if (alignment == Alignment::Center) {
auto padding_length = (width - original_length) / 2;
- builder.appendf("%*s%s%*s", padding_length, "", string.characters(), padding_length, "");
+ builder.appendf("%*s%s%*s", (int)padding_length, "", string.characters(), (int)padding_length, "");
if ((width - original_length) % 2)
builder.append(' ');
} else {
- format_builder.appendf("%%%s%zus", alignment == Alignment::Left ? "-" : "", width + (string.length() - original_length));
- builder.appendf(
- format_builder.to_string().characters(),
- string.characters());
+ builder.appendf(alignment == Alignment::Left ? "%-*s" : "%*s", (int)(width + (string.length() - original_length)), string.characters());
}
};
diff --git a/Libraries/LibRegex/RegexByteCode.cpp b/Libraries/LibRegex/RegexByteCode.cpp
index 551327f30e..63f526ee9a 100644
--- a/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Libraries/LibRegex/RegexByteCode.cpp
@@ -714,16 +714,16 @@ const Vector<String> OpCode_Compare::variable_arguments_to_string(Optional<Match
} else if (compare_type == CharacterCompareType::NamedReference) {
auto ptr = (const char*)m_bytecode->at(offset++);
auto length = m_bytecode->at(offset++);
- result.empend(String::format("name='%.*s'", length, ptr));
+ result.empend(String::format("name='%.*s'", (int)length, ptr));
} else if (compare_type == CharacterCompareType::Reference) {
auto ref = m_bytecode->at(offset++);
- result.empend(String::format("number=%lu", ref));
+ result.empend(String::formatted("number={}", ref));
} else if (compare_type == CharacterCompareType::String) {
auto& length = m_bytecode->at(offset++);
StringBuilder str_builder;
for (size_t i = 0; i < length; ++i)
str_builder.append(m_bytecode->at(offset++));
- result.empend(String::format("value=\"%.*s\"", length, str_builder.string_view().characters_without_null_termination()));
+ result.empend(String::format("value=\"%.*s\"", (int)length, str_builder.string_view().characters_without_null_termination()));
if (!view.is_null() && view.length() > state().string_position)
result.empend(String::format(
"compare against: \"%s\"",
diff --git a/Libraries/LibRegex/RegexByteCode.h b/Libraries/LibRegex/RegexByteCode.h
index dbb78cbf4b..940ed14a1c 100644
--- a/Libraries/LibRegex/RegexByteCode.h
+++ b/Libraries/LibRegex/RegexByteCode.h
@@ -532,7 +532,7 @@ public:
const String to_string() const
{
- return String::format("[0x%02X] %s", opcode_id(), name(opcode_id()));
+ return String::format("[0x%02X] %s", (int)opcode_id(), name(opcode_id()));
}
virtual const String arguments_string() const = 0;
@@ -618,7 +618,7 @@ public:
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
const String arguments_string() const override
{
- return String::format("offset=%i [&%lu]", offset(), state().instruction_position + size() + offset());
+ return String::format("offset=%zd [&%zu]", offset(), state().instruction_position + size() + offset());
}
};
@@ -634,7 +634,7 @@ public:
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
const String arguments_string() const override
{
- return String::format("offset=%i [&%lu], sp: %lu", offset(), state().instruction_position + size() + offset(), state().string_position);
+ return String::format("offset=%zd [&%zu], sp: %zu", offset(), state().instruction_position + size() + offset(), state().string_position);
}
};
@@ -650,7 +650,7 @@ public:
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
const String arguments_string() const override
{
- return String::format("offset=%i [&%lu], sp: %lu", offset(), state().instruction_position + size() + offset(), state().string_position);
+ return String::format("offset=%zd [&%zu], sp: %zu", offset(), state().instruction_position + size() + offset(), state().string_position);
}
};
@@ -689,7 +689,7 @@ public:
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t arguments_count() const { return 1; }
ALWAYS_INLINE BoundaryCheckType type() const { return static_cast<BoundaryCheckType>(argument(0)); }
- const String arguments_string() const override { return String::format("kind=%lu (%s)", argument(0), boundary_check_type_name(type())); }
+ const String arguments_string() const override { return String::format("kind=%lu (%s)", (long unsigned int)argument(0), boundary_check_type_name(type())); }
};
class OpCode_SaveLeftCaptureGroup final : public OpCode {
@@ -748,7 +748,7 @@ public:
ALWAYS_INLINE size_t length() const { return argument(1); }
const String arguments_string() const override
{
- return String::format("name=%s, length=%lu", name().to_string().characters(), length());
+ return String::format("name=%s, length=%zu", name().to_string().characters(), length());
}
};
diff --git a/Libraries/LibWeb/Loader/FrameLoader.cpp b/Libraries/LibWeb/Loader/FrameLoader.cpp
index 72598378d1..172a9e1b2a 100644
--- a/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -219,6 +219,9 @@ void FrameLoader::load_html(const StringView& html, const URL& url)
frame().set_document(&parser.document());
}
+// FIXME: Use an actual templating engine (our own one when it's built, preferably
+// with a way to check these usages at compile time)
+
void FrameLoader::load_error_page(const URL& failed_url, const String& error)
{
auto error_page_url = "file:///res/html/error.html";
@@ -226,10 +229,12 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error)
error_page_url,
[this, failed_url, error](auto data, auto&) {
ASSERT(!data.is_null());
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
auto html = String::format(
String::copy(data).characters(),
escape_html_entities(failed_url.to_string()).characters(),
escape_html_entities(error).characters());
+#pragma GCC diagnostic pop
auto document = HTML::parse_html_document(html, failed_url, "utf-8");
ASSERT(document);
frame().set_document(document);