diff options
author | tastytea | 2020-11-13 14:17:44 +0100 |
---|---|---|
committer | tastytea | 2020-11-13 14:17:44 +0100 |
commit | f4bd5abd0197fe04a813089ffa00c14ec68f999a (patch) | |
tree | 91241e5f798ca3c7a29ac3cbe14707ff152f7f9c | |
parent | c9211e621ec04bb1ecd052b8af6ac465c68cf242 (diff) | |
download | mastodonpp-f4bd5abd0197fe04a813089ffa00c14ec68f999a.tar mastodonpp-f4bd5abd0197fe04a813089ffa00c14ec68f999a.tar.gz mastodonpp-f4bd5abd0197fe04a813089ffa00c14ec68f999a.zip |
Fix some warnings.
Avoid copy, initialize members in header, initialize variables.
-rw-r--r-- | include/curl_wrapper.hpp | 8 | ||||
-rw-r--r-- | src/connection.cpp | 2 | ||||
-rw-r--r-- | src/curl_wrapper.cpp | 14 |
3 files changed, 9 insertions, 15 deletions
diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp index 37c8d4b..49b8ae0 100644 --- a/include/curl_wrapper.hpp +++ b/include/curl_wrapper.hpp @@ -245,11 +245,11 @@ protected: virtual void set_useragent(string_view useragent); private: - CURL *_connection; - char _curl_buffer_error[CURL_ERROR_SIZE]; + CURL *_connection{nullptr}; + char _curl_buffer_error[CURL_ERROR_SIZE]{'\0'}; string _curl_buffer_headers; string _curl_buffer_body; - bool _stream_cancelled; + bool _stream_cancelled{false}; /*! * @brief Initializes curl and sets up connection. @@ -297,7 +297,7 @@ private: * @since 0.1.0 */ int progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, - curl_off_t ultotal, curl_off_t ulnow); + curl_off_t ultotal, curl_off_t ulnow) const; //! @copydoc writer_body_wrapper static inline int progress_wrapper(void *f, void *clientp, diff --git a/src/connection.cpp b/src/connection.cpp index f2cd053..0b00ad5 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -70,7 +70,7 @@ string Connection::get_new_stream_contents() { _buffer_mutex.lock(); auto &buffer{get_buffer()}; - const string buffer_copy{buffer}; + string buffer_copy{buffer}; buffer.clear(); _buffer_mutex.unlock(); return buffer_copy; diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index 954006d..4ecbe7a 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -56,17 +56,11 @@ void CURLWrapper::init() } CURLWrapper::CURLWrapper() - : _connection{} - , _curl_buffer_error{} - , _stream_cancelled{false} { init(); } CURLWrapper::CURLWrapper(const CURLWrapper &) - : _connection{} - , _curl_buffer_error{} - , _stream_cancelled{false} { init(); } @@ -90,7 +84,7 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, _curl_buffer_headers.clear(); _curl_buffer_body.clear(); - CURLcode code; + CURLcode code{CURLE_OK}; switch (method) { case http_method::GET: @@ -186,7 +180,7 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, if (code == CURLE_OK || (code == CURLE_ABORTED_BY_CALLBACK && _stream_cancelled)) { - long http_status; // NOLINT(google-runtime-int) + long http_status{0}; // NOLINT(google-runtime-int) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status); answer.http_status = static_cast<uint16_t>(http_status); @@ -281,8 +275,8 @@ void CURLWrapper::set_cainfo(const string_view path) void CURLWrapper::set_useragent(const string_view useragent) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) CURLcode code{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) curl_easy_setopt(_connection, CURLOPT_USERAGENT, useragent.data())}; if (code != CURLE_OK) { @@ -319,7 +313,7 @@ size_t CURLWrapper::writer_header(char *data, size_t size, size_t nmemb) } int CURLWrapper::progress(void *, curl_off_t, curl_off_t, curl_off_t, - curl_off_t) + curl_off_t) const { if (_stream_cancelled) { |