Fix compilation on GCC

This commit is contained in:
blankie 2023-11-25 15:22:06 +11:00
parent 74a3eb2ae0
commit 0dd921cd5d
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 17 additions and 9 deletions

View File

@ -266,7 +266,7 @@ long MastodonClient::_response_status_code() {
static void lowercase(std::string& str) { static void lowercase(std::string& str) {
for (size_t i = 0; i < str.size(); i++) { for (size_t i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') { if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = str[i] - 'A' + 'a'; str[i] = str[i] - static_cast<char>('A' + 'a');
} }
} }
} }

View File

@ -7,6 +7,7 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wshadow"
#include <lexbor/html/html.h> #include <lexbor/html/html.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@ -49,13 +50,13 @@ public:
lxb_html_document_destroy(this->_document); 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* node = lxb_dom_interface_node(this->_document);
lxb_dom_node_t* html = lxb_dom_node_first_child(node); lxb_dom_node_t* html = lxb_dom_node_first_child(node);
lxb_dom_node_t* body = lxb_dom_node_last_child(html); lxb_dom_node_t* body = lxb_dom_node_last_child(html);
return body; 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(); lxb_dom_node_t* body = this->body();
assert(body->type == LXB_DOM_NODE_TYPE_ELEMENT); assert(body->type == LXB_DOM_NODE_TYPE_ELEMENT);
return lxb_dom_interface_element(body); return lxb_dom_interface_element(body);

View File

@ -159,9 +159,12 @@ time_t parse_rfc3339(const std::string& str) {
.tm_mday = to_int(sm.str(3)), .tm_mday = to_int(sm.str(3)),
.tm_mon = to_int(sm.str(2)) - 1, .tm_mon = to_int(sm.str(2)) - 1,
.tm_year = to_int(sm.str(1)) - 1900, .tm_year = to_int(sm.str(1)) - 1900,
.tm_wday = -1,
.tm_yday = -1,
.tm_isdst = -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_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); time_t time = mktime(&tm);
if (time == -1) { if (time == -1) {

View File

@ -15,7 +15,7 @@
static inline void preprocess_html(const httplib::Request& req, const std::string& domain_name, const std::vector<Emoji>& emojis, lxb_dom_element_t* element); static inline void preprocess_html(const httplib::Request& req, const std::string& domain_name, const std::vector<Emoji>& 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 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<Emoji>& emojis); static inline lxb_dom_node_t* emojify(lxb_dom_node_t* child, const std::vector<Emoji>& emojis);
static inline std::vector<lxb_dom_node*> emojify(lxb_dom_document_t* document, std::string str, const std::vector<Emoji>& emojis); static inline std::vector<lxb_dom_node*> emojify(lxb_dom_document_t* document, std::string str, const std::vector<Emoji>& emojis);
@ -133,10 +133,14 @@ std::string proxy_mastodon_url(const httplib::Request& req, const std::string& u
throw std::bad_alloc(); throw std::bad_alloc();
} }
// 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); CURLUcode code = curl_url_set(url.get(), CURLUPART_URL, url_str.c_str(), 0);
if (code) { if (code) {
throw CurlUrlException(code); throw CurlUrlException(code);
} }
}
auto get_part = [&](CURLUPart part, CURLUcode ignore = CURLUE_OK) { auto get_part = [&](CURLUPart part, CURLUcode ignore = CURLUE_OK) {
char* content = nullptr; char* content = nullptr;
@ -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 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 // https://vt.social/@LucydiaLuminous/111448085044245037
if (std::regex_search(cls, unhandled_link_re)) { if (std::regex_search(element_cls, unhandled_link_re)) {
return true; return true;
} }