From 0dd921cd5dae71cba50f19787acc96ec8a30b324 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 25 Nov 2023 15:22:06 +1100 Subject: [PATCH] Fix compilation on GCC --- client.cpp | 2 +- lxb_wrapper.h | 5 +++-- models.cpp | 3 +++ servehelper.cpp | 16 ++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/client.cpp b/client.cpp index e43ae21..b4b0c1f 100644 --- a/client.cpp +++ b/client.cpp @@ -266,7 +266,7 @@ long MastodonClient::_response_status_code() { static void lowercase(std::string& str) { for (size_t i = 0; i < str.size(); i++) { if (str[i] >= 'A' && str[i] <= 'Z') { - str[i] = str[i] - 'A' + 'a'; + str[i] = str[i] - static_cast('A' + 'a'); } } } diff --git a/lxb_wrapper.h b/lxb_wrapper.h index cd32123..5008f86 100644 --- a/lxb_wrapper.h +++ b/lxb_wrapper.h @@ -7,6 +7,7 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wshadow" #include #pragma GCC diagnostic pop @@ -49,13 +50,13 @@ public: lxb_html_document_destroy(this->_document); } - constexpr lxb_dom_node_t* body() const noexcept { + inline lxb_dom_node_t* body() const noexcept { lxb_dom_node_t* node = lxb_dom_interface_node(this->_document); lxb_dom_node_t* html = lxb_dom_node_first_child(node); lxb_dom_node_t* body = lxb_dom_node_last_child(html); return body; } - constexpr lxb_dom_element_t* body_element() const noexcept { + inline lxb_dom_element_t* body_element() const noexcept { lxb_dom_node_t* body = this->body(); assert(body->type == LXB_DOM_NODE_TYPE_ELEMENT); return lxb_dom_interface_element(body); diff --git a/models.cpp b/models.cpp index 7dcb122..31201f7 100644 --- a/models.cpp +++ b/models.cpp @@ -159,9 +159,12 @@ time_t parse_rfc3339(const std::string& str) { .tm_mday = to_int(sm.str(3)), .tm_mon = to_int(sm.str(2)) - 1, .tm_year = to_int(sm.str(1)) - 1900, + .tm_wday = -1, + .tm_yday = -1, .tm_isdst = -1, .tm_gmtoff = !sm.str(7).empty() ? 0 : to_int(sm.str(8)) * 60 * 60 + to_int(sm.str(9)) * 60, + .tm_zone = nullptr, }; time_t time = mktime(&tm); if (time == -1) { diff --git a/servehelper.cpp b/servehelper.cpp index a20bac9..4f0cf91 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -15,7 +15,7 @@ static inline void preprocess_html(const httplib::Request& req, const std::string& domain_name, const std::vector& emojis, lxb_dom_element_t* element); static inline void preprocess_link(const httplib::Request& req, const std::string& domain_name, lxb_dom_element_t* element); -static inline bool should_fix_link(lxb_dom_element_t* element, const std::string& cls); +static inline bool should_fix_link(lxb_dom_element_t* element, const std::string& element_cls); static inline lxb_dom_node_t* emojify(lxb_dom_node_t* child, const std::vector& emojis); static inline std::vector emojify(lxb_dom_document_t* document, std::string str, const std::vector& emojis); @@ -133,9 +133,13 @@ std::string proxy_mastodon_url(const httplib::Request& req, const std::string& u throw std::bad_alloc(); } - CURLUcode code = curl_url_set(url.get(), CURLUPART_URL, url_str.c_str(), 0); - if (code) { - throw CurlUrlException(code); + // in a block to avoid a (potential) gcc bug where it thinks the lambda below + // shadows `code`, even if i do `[&url](...) { ... }` + { + CURLUcode code = curl_url_set(url.get(), CURLUPART_URL, url_str.c_str(), 0); + if (code) { + throw CurlUrlException(code); + } } auto get_part = [&](CURLUPart part, CURLUcode ignore = CURLUE_OK) { @@ -266,9 +270,9 @@ static inline void preprocess_link(const httplib::Request& req, const std::strin } static std::regex unhandled_link_re("\\bunhandled-link\\b"); -static inline bool should_fix_link(lxb_dom_element_t* element, const std::string& cls) { +static inline bool should_fix_link(lxb_dom_element_t* element, const std::string& element_cls) { // https://vt.social/@LucydiaLuminous/111448085044245037 - if (std::regex_search(cls, unhandled_link_re)) { + if (std::regex_search(element_cls, unhandled_link_re)) { return true; }