srctree

Robin Linden parent 4b57d29e d08d18b0
meta/clang-tidy: Enable readability-implicit-bool-conversion

.clang-tidy added: 52, removed: 48, total 4
@@ -45,6 +45,7 @@ Checks: >
readability-duplicate-include,
readability-else-after-return,
readability-identifier-naming,
readability-implicit-bool-conversion,
readability-inconsistent-declaration-parameter-name,
readability-isolate-declaration,
readability-make-member-function-const,
 
browser/gui/app.cpp added: 52, removed: 48, total 4
@@ -88,7 +88,7 @@ std::optional<std::string_view> try_get_uri(layout::LayoutBox const *from) {
 
for (auto const *node = from->node; node != nullptr; node = node->parent) {
auto const *element = std::get_if<dom::Element>(&node->node);
if (element && element->name == "a"sv && element->attributes.contains("href")) {
if ((element != nullptr) && element->name == "a"sv && element->attributes.contains("href")) {
return element->attributes.at("href");
}
}
@@ -238,7 +238,7 @@ App::App(std::string browser_title, std::string start_page_hint, bool load_start
 
// This is okay as long as we don't call e.g. setenv(), unsetenv(), or putenv().
// NOLINTNEXTLINE(concurrency-mt-unsafe)
if (std::getenv("HST_DISABLE_DISK_IO")) {
if (std::getenv("HST_DISABLE_DISK_IO") != nullptr) {
// TODO(robinlinden): Support for things like HST_DISABLE_DISK_IO=0 to
// re-enable IO.
ImGui::GetIO().IniFilename = nullptr;
 
engine/engine_test.cpp added: 52, removed: 48, total 4
@@ -143,7 +143,7 @@ int main() {
engine::Engine e{std::make_unique<FakeProtocolHandler>(std::move(responses))};
e.navigate(uri::Uri::parse("hax://example.com"));
// Our default CSS gives <html> the property display: block.
require(e.layout());
require(e.layout() != nullptr);
expect_eq(e.layout()->get_property<css::PropertyId::Display>(), style::DisplayValue::Block);
 
responses = std::map<std::string, Response>{{
@@ -160,7 +160,7 @@ int main() {
 
// The CSS declared in the page should have a higher priority and give
// <html> the property display: inline.
require(e.layout());
require(e.layout() != nullptr);
expect_eq(e.layout()->get_property<css::PropertyId::Display>(), style::DisplayValue::Inline);
});
 
@@ -181,7 +181,7 @@ int main() {
}};
engine::Engine e{std::make_unique<FakeProtocolHandler>(std::move(responses))};
e.navigate(uri::Uri::parse("hax://example.com"));
require(e.layout());
require(e.layout() != nullptr);
auto const *a = dom::nodes_by_xpath(*e.layout(), "//a"sv).at(0);
expect_eq(a->get_property<css::PropertyId::Color>(), gfx::Color::from_css_name("red"));
auto const *p = dom::nodes_by_xpath(*e.layout(), "//p"sv).at(0);
 
html2/parser_states.cpp added: 52, removed: 48, total 4
@@ -386,27 +386,27 @@ std::optional<InsertionMode> InHeadNoscript::process(IActions &a, html2::Token c
}
 
auto const *start = std::get_if<html2::StartTagToken>(&token);
if (start && start->tag_name == "html") {
if (start != nullptr && start->tag_name == "html") {
return InBody{}.process(a, token);
}
 
auto const *end = std::get_if<html2::EndTagToken>(&token);
if (end && end->tag_name == "noscript") {
if (end != nullptr && end->tag_name == "noscript") {
assert(a.current_node_name() == "noscript");
a.pop_current_node();
return InHead{};
}
 
static constexpr std::array kInHeadElements{"basefont"sv, "bgsound"sv, "link"sv, "meta"sv, "noframes"sv, "style"sv};
if ((start && is_in_array<kInHeadElements>(start->tag_name)) || std::holds_alternative<html2::CommentToken>(token)
|| is_boring_whitespace(token)) {
if ((start != nullptr && is_in_array<kInHeadElements>(start->tag_name))
|| std::holds_alternative<html2::CommentToken>(token) || is_boring_whitespace(token)) {
return InHead{}.process(a, token);
}
 
static constexpr std::array kIgnoredStartTags{"head"sv, "noscript"sv};
if (end && end->tag_name == "br") {
if (end != nullptr && end->tag_name == "br") {
// Let the anything-else case handle this.
} else if (start && is_in_array<kIgnoredStartTags>(start->tag_name)) {
} else if (start != nullptr && is_in_array<kIgnoredStartTags>(start->tag_name)) {
// Parse error, ignore the token.
return {};
}
@@ -460,7 +460,7 @@ std::optional<InsertionMode> AfterHead::process(IActions &a, html2::Token const
 
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
std::optional<InsertionMode> InBody::process(IActions &a, html2::Token const &token) {
if (auto const *start = std::get_if<html2::StartTagToken>(&token); start && start->tag_name == "html") {
if (auto const *start = std::get_if<html2::StartTagToken>(&token); start != nullptr && start->tag_name == "html") {
// Parse error.
// TODO(robinlinden): If there is a template element on the stack of open elements, then ignore the token.
 
 
img/gif.cpp added: 52, removed: 48, total 4
@@ -67,9 +67,9 @@ struct ScreenDescriptor {
return std::nullopt;
}
 
screen.global_color_table = packed_fields & 0b1000'0000;
screen.global_color_table = (packed_fields & 0b1000'0000) != 0;
screen.color_resolution = (packed_fields & 0b0111'0000) >> 4;
screen.sort = packed_fields & 0b0000'1000;
screen.sort = (packed_fields & 0b0000'1000) != 0;
screen.size_of_global_color_table = packed_fields & 0b0000'0111;
 
if (!is.read(reinterpret_cast<char *>(&screen.background_color_index), sizeof(screen.background_color_index))) {
 
img/img_example.cpp added: 52, removed: 48, total 4
@@ -47,7 +47,7 @@ struct PixelDataGetter {
 
int main(int argc, char **argv) {
if (argc != 2 && argc != 3) {
std::cerr << "Usage: " << (argv[0] ? argv[0] : "<bin>") << " [--metadata] <image_file>\n";
std::cerr << "Usage: " << (argv[0] != nullptr ? argv[0] : "<bin>") << " [--metadata] <image_file>\n";
return 1;
}
 
 
layout/layout.cpp added: 52, removed: 48, total 4
@@ -230,7 +230,7 @@ void Layouter::layout_inline(LayoutBox &box, geom::Rect const &bounds) const {
}
}
 
if (box.node->parent) {
if (box.node->parent != nullptr) {
auto const &d = box.dimensions;
box.dimensions.content.x = bounds.x + d.padding.left + d.border.left + d.margin.left;
box.dimensions.content.y = bounds.y + d.border.top + d.padding.top + d.margin.top;
 
layout/layout_box.cpp added: 52, removed: 48, total 4
@@ -83,7 +83,7 @@ void print_box(LayoutBox const &box, std::ostream &os, std::uint8_t depth = 0) {
 
int get_root_font_size(style::StyledNode const &node) {
auto const *n = &node;
while (n->parent) {
while (n->parent != nullptr) {
n = n->parent;
}
return n->get_property<css::PropertyId::FontSize>();
 
os/system_info_linux_test.cpp added: 52, removed: 48, total 4
@@ -29,19 +29,21 @@ int main() {
unsetenv("ELM_SCALE");
 
s.add_test("active_window_scale_factor", [](etest::IActions &a) {
static constexpr int kOnlyIfUnset = 0;
 
// We default to 1 when no GUI toolkit has an opinion.
a.expect_eq(os::active_window_scale_factor(), 1u);
 
setenv("ELM_SCALE", "2", false);
setenv("ELM_SCALE", "2", kOnlyIfUnset);
a.expect_eq(os::active_window_scale_factor(), 2u);
 
setenv("GDK_SCALE", "5", false);
setenv("GDK_SCALE", "5", kOnlyIfUnset);
a.expect_eq(os::active_window_scale_factor(), 5u);
 
setenv("QT_SCALE_FACTOR", "10", false);
setenv("QT_SCALE_FACTOR", "10", kOnlyIfUnset);
a.expect_eq(os::active_window_scale_factor(), 10u);
 
setenv("HST_SCALE", "50", false);
setenv("HST_SCALE", "50", kOnlyIfUnset);
a.expect_eq(os::active_window_scale_factor(), 50u);
});
 
 
os/xdg_linux_test.cpp added: 52, removed: 48, total 4
@@ -22,6 +22,8 @@
// NOLINTBEGIN(concurrency-mt-unsafe): No threads here.
 
int main() {
static constexpr int kOnlyIfUnset = 0;
 
// Ensure that the system's environment doesn't affect the test result.
unsetenv("HOME");
unsetenv("XDG_DATA_HOME");
@@ -32,7 +34,7 @@ int main() {
 
s.add_test("HOME", [&](etest::IActions &a) {
static constexpr auto kHome = "/home";
setenv("HOME", kHome, false);
setenv("HOME", kHome, kOnlyIfUnset);
 
a.expect(std::ranges::find_if(font_paths_without_env_vars, [](auto const &path) {
return path.contains(kHome);
@@ -46,7 +48,7 @@ int main() {
 
s.add_test("XDG_DATA_HOME", [&](etest::IActions &a) {
static constexpr auto kXdgDataHome = "/xdg_data_home";
setenv("XDG_DATA_HOME", kXdgDataHome, false);
setenv("XDG_DATA_HOME", kXdgDataHome, kOnlyIfUnset);
 
a.expect(std::ranges::find_if(font_paths_without_env_vars, [](auto const &path) {
return path.contains(kXdgDataHome);
 
style/styled_node.cpp added: 52, removed: 48, total 4
@@ -552,12 +552,12 @@ int StyledNode::get_font_size_property() const {
if (unit == "rem") {
auto const *root = [&] {
auto const *n = closest->second;
while (n->parent) {
while (n->parent != nullptr) {
n = n->parent;
}
return n;
}();
auto root_font_size = root && root != this ? root->get_font_size_property() : kDefaultFontSize;
auto root_font_size = (root != nullptr) && root != this ? root->get_font_size_property() : kDefaultFontSize;
return static_cast<int>(value * root_font_size);
}
 
 
url/url.cpp added: 52, removed: 48, total 4
@@ -804,8 +804,7 @@ void UrlParser::state_host() {
return;
}
 
if (state_override_.has_value() && buffer_.empty()
&& (url_.includes_credentials() || url_.port.has_value())) {
if (state_override_.has_value() && buffer_.empty() && (url_.includes_credentials() || url_.port.has_value())) {
state_ = ParserState::Terminate;
 
return;
@@ -1188,7 +1187,7 @@ std::optional<std::string> UrlParser::domain_to_ascii(std::string_view domain, b
 
auto *uts = icu::IDNA::createUTS46Instance(opts, err);
 
if (U_FAILURE(err)) {
if (U_FAILURE(err) != 0) {
std::cerr << "Failed to create UTS46 instance: " << u_errorName(err) << '\n' << std::flush;
return std::nullopt;
}
@@ -1213,7 +1212,7 @@ std::optional<std::string> UrlParser::domain_to_ascii(std::string_view domain, b
}
 
// If domain or any label is empty, proc_err should contain UIDNA_ERROR_EMPTY_LABEL
if (U_FAILURE(err) || proc_err != 0 || ascii_domain.empty()) {
if ((U_FAILURE(err) != 0) || proc_err != 0 || ascii_domain.empty()) {
validation_error(ValidationError::DomainToAscii);
 
return std::nullopt;
 
wasm/leb128.h added: 52, removed: 48, total 4
@@ -52,7 +52,7 @@ struct Leb128<T> {
}
 
result |= static_cast<T>(byte & 0b0111'1111) << shift;
if (!(byte & 0b1000'0000)) {
if ((byte & 0b1000'0000) == 0) {
return result;
}
 
@@ -94,16 +94,16 @@ struct Leb128<T> {
 
result |= static_cast<T>(byte & kNonContinuationBits) << shift;
shift += 7;
if (!(byte & kContinuationBit)) {
if ((byte & kContinuationBit) == 0) {
break;
}
}
 
if (byte & kContinuationBit) {
if ((byte & kContinuationBit) != 0) {
return tl::unexpected{Leb128ParseError::Invalid};
}
 
if ((shift < sizeof(T) * 8) && (byte & kSignBit)) {
if ((shift < sizeof(T) * 8) && ((byte & kSignBit) != 0)) {
result |= ~T{0} << shift;
}
 
 
wasm/wasm_example.cpp added: 52, removed: 48, total 4
@@ -47,7 +47,7 @@ std::ostream &operator<<(std::ostream &os, wasm::ValueType type) {
 
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Usage: " << (argv[0] ? argv[0] : "<bin>") << ' ' << "<wasm_file>\n";
std::cerr << "Usage: " << (argv[0] != nullptr ? argv[0] : "<bin>") << ' ' << "<wasm_file>\n";
return 1;
}