mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +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
Notes:
sideshowbarker
2024-07-18 23:55:55 +09:00
Author: https://github.com/ccapitalK Commit: https://github.com/SerenityOS/serenity/commit/fe2b8906d47 Pull-request: https://github.com/SerenityOS/serenity/pull/4900
7 changed files with 21 additions and 21 deletions
|
@ -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("), ");
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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\"",
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue