mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +00:00
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.
This commit is contained in:
parent
6d97b623cd
commit
fe2b8906d4
7 changed files with 21 additions and 21 deletions
|
@ -1356,7 +1356,7 @@ String Style::to_string() const
|
||||||
if (m_foreground.m_is_rgb) {
|
if (m_foreground.m_is_rgb) {
|
||||||
builder.join(", ", m_foreground.m_rgb_color);
|
builder.join(", ", m_foreground.m_rgb_color);
|
||||||
} else {
|
} else {
|
||||||
builder.appendf("(XtermColor) %d", m_foreground.m_xterm_color);
|
builder.appendf("(XtermColor) %d", (int)m_foreground.m_xterm_color);
|
||||||
}
|
}
|
||||||
builder.append("), ");
|
builder.append("), ");
|
||||||
}
|
}
|
||||||
|
@ -1366,7 +1366,7 @@ String Style::to_string() const
|
||||||
if (m_background.m_is_rgb) {
|
if (m_background.m_is_rgb) {
|
||||||
builder.join(' ', m_background.m_rgb_color);
|
builder.join(' ', m_background.m_rgb_color);
|
||||||
} else {
|
} else {
|
||||||
builder.appendf("(XtermColor) %d", m_background.m_xterm_color);
|
builder.appendf("(XtermColor) %d", (int)m_background.m_xterm_color);
|
||||||
}
|
}
|
||||||
builder.append("), ");
|
builder.append("), ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ void XtermSuggestionDisplay::display(const SuggestionManager& manager)
|
||||||
if (m_pages.size() > 1) {
|
if (m_pages.size() > 1) {
|
||||||
auto left_arrow = page_index > 0 ? '<' : ' ';
|
auto left_arrow = page_index > 0 ? '<' : ' ';
|
||||||
auto right_arrow = page_index < m_pages.size() - 1 ? '>' : ' ';
|
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) {
|
if (string.length() > m_num_columns - 1) {
|
||||||
// This would overflow into the next line, so just don't print an indicator.
|
// This would overflow into the next line, so just don't print an indicator.
|
||||||
|
|
|
@ -32,9 +32,9 @@ namespace Markdown {
|
||||||
String Heading::render_to_html() const
|
String Heading::render_to_html() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendf("<h%d>", m_level);
|
builder.appendf("<h%zu>", m_level);
|
||||||
builder.append(m_text.render_to_html());
|
builder.append(m_text.render_to_html());
|
||||||
builder.appendf("</h%d>\n", m_level);
|
builder.appendf("</h%zu>\n", m_level);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ namespace Markdown {
|
||||||
String Table::render_for_terminal(size_t view_width) const
|
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);
|
auto unit_width_length = view_width == 0 ? 4 : ((float)(view_width - m_columns.size()) / (float)m_total_width);
|
||||||
StringBuilder format_builder;
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
auto write_aligned = [&](const auto& text, auto width, auto alignment) {
|
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())
|
for (auto& span : text.spans())
|
||||||
original_length += span.text.length();
|
original_length += span.text.length();
|
||||||
auto string = text.render_for_terminal();
|
auto string = text.render_for_terminal();
|
||||||
format_builder.clear();
|
|
||||||
if (alignment == Alignment::Center) {
|
if (alignment == Alignment::Center) {
|
||||||
auto padding_length = (width - original_length) / 2;
|
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)
|
if ((width - original_length) % 2)
|
||||||
builder.append(' ');
|
builder.append(' ');
|
||||||
} else {
|
} else {
|
||||||
format_builder.appendf("%%%s%zus", alignment == Alignment::Left ? "-" : "", width + (string.length() - original_length));
|
builder.appendf(alignment == Alignment::Left ? "%-*s" : "%*s", (int)(width + (string.length() - original_length)), string.characters());
|
||||||
builder.appendf(
|
|
||||||
format_builder.to_string().characters(),
|
|
||||||
string.characters());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -714,16 +714,16 @@ const Vector<String> OpCode_Compare::variable_arguments_to_string(Optional<Match
|
||||||
} else if (compare_type == CharacterCompareType::NamedReference) {
|
} else if (compare_type == CharacterCompareType::NamedReference) {
|
||||||
auto ptr = (const char*)m_bytecode->at(offset++);
|
auto ptr = (const char*)m_bytecode->at(offset++);
|
||||||
auto length = 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) {
|
} else if (compare_type == CharacterCompareType::Reference) {
|
||||||
auto ref = m_bytecode->at(offset++);
|
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) {
|
} else if (compare_type == CharacterCompareType::String) {
|
||||||
auto& length = m_bytecode->at(offset++);
|
auto& length = m_bytecode->at(offset++);
|
||||||
StringBuilder str_builder;
|
StringBuilder str_builder;
|
||||||
for (size_t i = 0; i < length; ++i)
|
for (size_t i = 0; i < length; ++i)
|
||||||
str_builder.append(m_bytecode->at(offset++));
|
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)
|
if (!view.is_null() && view.length() > state().string_position)
|
||||||
result.empend(String::format(
|
result.empend(String::format(
|
||||||
"compare against: \"%s\"",
|
"compare against: \"%s\"",
|
||||||
|
|
|
@ -532,7 +532,7 @@ public:
|
||||||
|
|
||||||
const String to_string() const
|
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;
|
virtual const String arguments_string() const = 0;
|
||||||
|
@ -618,7 +618,7 @@ public:
|
||||||
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
|
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
|
||||||
const String arguments_string() const override
|
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); }
|
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
|
||||||
const String arguments_string() const override
|
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); }
|
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
|
||||||
const String arguments_string() const override
|
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 size() const override { return 2; }
|
||||||
ALWAYS_INLINE size_t arguments_count() const { return 1; }
|
ALWAYS_INLINE size_t arguments_count() const { return 1; }
|
||||||
ALWAYS_INLINE BoundaryCheckType type() const { return static_cast<BoundaryCheckType>(argument(0)); }
|
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 {
|
class OpCode_SaveLeftCaptureGroup final : public OpCode {
|
||||||
|
@ -748,7 +748,7 @@ public:
|
||||||
ALWAYS_INLINE size_t length() const { return argument(1); }
|
ALWAYS_INLINE size_t length() const { return argument(1); }
|
||||||
const String arguments_string() const override
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,9 @@ void FrameLoader::load_html(const StringView& html, const URL& url)
|
||||||
frame().set_document(&parser.document());
|
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)
|
void FrameLoader::load_error_page(const URL& failed_url, const String& error)
|
||||||
{
|
{
|
||||||
auto error_page_url = "file:///res/html/error.html";
|
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,
|
error_page_url,
|
||||||
[this, failed_url, error](auto data, auto&) {
|
[this, failed_url, error](auto data, auto&) {
|
||||||
ASSERT(!data.is_null());
|
ASSERT(!data.is_null());
|
||||||
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||||
auto html = String::format(
|
auto html = String::format(
|
||||||
String::copy(data).characters(),
|
String::copy(data).characters(),
|
||||||
escape_html_entities(failed_url.to_string()).characters(),
|
escape_html_entities(failed_url.to_string()).characters(),
|
||||||
escape_html_entities(error).characters());
|
escape_html_entities(error).characters());
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
auto document = HTML::parse_html_document(html, failed_url, "utf-8");
|
auto document = HTML::parse_html_document(html, failed_url, "utf-8");
|
||||||
ASSERT(document);
|
ASSERT(document);
|
||||||
frame().set_document(document);
|
frame().set_document(document);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue