Skip to content

Commit 7c051c4

Browse files
committed
cppcheck and clang-tidy fixes for Fedora43
1 parent a298184 commit 7c051c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+343
-353
lines changed

.clang-tidy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ Checks: '*,
3838
-cppcoreguidelines-avoid-do-while,
3939
-llvmlibc-inline-function-decl,
4040
-altera-struct-pack-align,
41-
-boost-use-ranges
41+
-boost-use-ranges,
42+
-cppcoreguidelines-special-member-functions,
43+
-hicpp-special-member-functions,
44+
-misc-header-include-cycle,
45+
-cppcoreguidelines-avoid-const-or-ref-data-members,
46+
-google-explicit-constructor,
47+
-hicpp-explicit-conversions
4248
'
4349
WarningsAsErrors: '*'
44-
HeaderFilterRegex: 'src\/*.hpp'
50+
HeaderFilterRegex: 'include\/cpr\/.*\.h(pp)?'
4551
FormatStyle: file

cppcheck-suppressions.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@
3939
<suppress>
4040
<id>postfixOperator</id>
4141
</suppress>
42+
<suppress>
43+
<id>syntaxError</id>
44+
<fileName>*/cpr/util.cpp</fileName>
45+
</suppress>
4246
</suppressions>

cpr/async.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
namespace cpr {
44

55
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
6-
CPR_SINGLETON_IMPL(GlobalThreadPool)
6+
CPR_SINGLETON_IMPL(GlobalThreadPool);
77

88
} // namespace cpr

cpr/callback.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <functional>
44

55
namespace cpr {
6-
76
void CancellationCallback::SetProgressCallback(ProgressCallback& u_cb) {
87
user_cb.emplace(std::reference_wrapper{u_cb});
98
}
9+
1010
bool CancellationCallback::operator()(cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, cpr_pf_arg_t ultotal, cpr_pf_arg_t ulnow) const {
11-
const bool cont_operation{!cancellation_state->load()};
12-
return user_cb ? (cont_operation && (*user_cb)(dltotal, dlnow, ultotal, ulnow)) : cont_operation;
11+
const bool const_operation = !(cancellation_state->load());
12+
return user_cb ? (const_operation && (*user_cb)(dltotal, dlnow, ultotal, ulnow)) : const_operation;
1313
}
1414
} // namespace cpr

cpr/cprtypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "cpr/cprtypes.h"
2-
32
#include <algorithm>
43
#include <cctype>
54
#include <string>
65

6+
77
namespace cpr {
88
bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string& b) const noexcept {
99
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](unsigned char ac, unsigned char bc) { return std::tolower(ac) < std::tolower(bc); });

cpr/curlholder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CurlHolder::CurlHolder() {
2222
assert(handle);
2323
}
2424

25-
CurlHolder::CurlHolder(CurlHolder&& old) noexcept : handle(old.handle), chunk(old.chunk), resolveCurlList(old.resolveCurlList), multipart(old.multipart), error(std::move(old.error)) {
25+
CurlHolder::CurlHolder(CurlHolder&& old) noexcept : handle(old.handle), chunk(old.chunk), resolveCurlList(old.resolveCurlList), multipart(old.multipart), error(old.error) {
2626
// Avoid double free
2727
old.handle = nullptr;
2828
old.chunk = nullptr;
@@ -49,7 +49,7 @@ CurlHolder& CurlHolder::operator=(CurlHolder&& old) noexcept {
4949
chunk = old.chunk;
5050
resolveCurlList = old.resolveCurlList;
5151
multipart = old.multipart;
52-
error = std::move(old.error);
52+
error = old.error;
5353

5454
// Avoid double free
5555
old.handle = nullptr;

cpr/error.cpp

Lines changed: 73 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,220 +4,223 @@
44
#include <curl/curlver.h>
55

66
namespace cpr {
7+
// NOLINTBEGIN(bugprone-branch-clone) Fine in this case
78
ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) {
8-
switch (curl_code)
9-
{
9+
switch (curl_code) {
1010
case CURLE_OK:
11-
return ErrorCode::OK;
11+
return ErrorCode::OK;
1212
case CURLE_UNSUPPORTED_PROTOCOL:
13-
return ErrorCode::UNSUPPORTED_PROTOCOL;
13+
return ErrorCode::UNSUPPORTED_PROTOCOL;
1414
case CURLE_FAILED_INIT:
15-
return ErrorCode::FAILED_INIT;
15+
return ErrorCode::FAILED_INIT;
1616
case CURLE_URL_MALFORMAT:
17-
return ErrorCode::URL_MALFORMAT;
17+
return ErrorCode::URL_MALFORMAT;
1818
case CURLE_NOT_BUILT_IN:
19-
return ErrorCode::NOT_BUILT_IN;
19+
return ErrorCode::NOT_BUILT_IN;
2020
case CURLE_COULDNT_RESOLVE_PROXY:
21-
return ErrorCode::COULDNT_RESOLVE_PROXY;
21+
return ErrorCode::COULDNT_RESOLVE_PROXY;
2222
case CURLE_COULDNT_RESOLVE_HOST:
23-
return ErrorCode::COULDNT_RESOLVE_HOST;
23+
return ErrorCode::COULDNT_RESOLVE_HOST;
2424
case CURLE_COULDNT_CONNECT:
25-
return ErrorCode::COULDNT_CONNECT;
26-
25+
return ErrorCode::COULDNT_CONNECT;
26+
2727
// Name changed in curl >= 7.51.0.
2828
#if LIBCURL_VERSION_NUM >= 0x073300
2929
case CURLE_WEIRD_SERVER_REPLY:
30-
return ErrorCode::WEIRD_SERVER_REPLY;
30+
return ErrorCode::WEIRD_SERVER_REPLY;
3131
#else
3232
case CURLE_FTP_WEIRD_SERVER_REPLY:
33-
return ErrorCode::WEIRD_SERVER_REPLY;
33+
return ErrorCode::WEIRD_SERVER_REPLY;
3434
#endif
35+
3536
case CURLE_REMOTE_ACCESS_DENIED:
36-
return ErrorCode::REMOTE_ACCESS_DENIED;
37+
return ErrorCode::REMOTE_ACCESS_DENIED;
3738
case CURLE_HTTP2:
38-
return ErrorCode::HTTP2;
39+
return ErrorCode::HTTP2;
3940
case CURLE_QUOTE_ERROR:
40-
return ErrorCode::QUOTE_ERROR;
41+
return ErrorCode::QUOTE_ERROR;
4142
case CURLE_HTTP_RETURNED_ERROR:
42-
return ErrorCode::HTTP_RETURNED_ERROR;
43+
return ErrorCode::HTTP_RETURNED_ERROR;
4344
case CURLE_WRITE_ERROR:
44-
return ErrorCode::WRITE_ERROR;
45+
return ErrorCode::WRITE_ERROR;
4546
case CURLE_UPLOAD_FAILED:
46-
return ErrorCode::UPLOAD_FAILED;
47+
return ErrorCode::UPLOAD_FAILED;
4748
case CURLE_READ_ERROR:
48-
return ErrorCode::READ_ERROR;
49+
return ErrorCode::READ_ERROR;
4950
case CURLE_OUT_OF_MEMORY:
50-
return ErrorCode::OUT_OF_MEMORY;
51+
return ErrorCode::OUT_OF_MEMORY;
5152
case CURLE_OPERATION_TIMEDOUT:
52-
return ErrorCode::OPERATION_TIMEDOUT;
53+
return ErrorCode::OPERATION_TIMEDOUT;
5354
case CURLE_RANGE_ERROR:
54-
return ErrorCode::RANGE_ERROR;
55+
return ErrorCode::RANGE_ERROR;
5556
case CURLE_HTTP_POST_ERROR:
56-
return ErrorCode::HTTP_POST_ERROR;
57+
return ErrorCode::HTTP_POST_ERROR;
5758
case CURLE_SSL_CONNECT_ERROR:
58-
return ErrorCode::SSL_CONNECT_ERROR;
59+
return ErrorCode::SSL_CONNECT_ERROR;
5960
case CURLE_BAD_DOWNLOAD_RESUME:
60-
return ErrorCode::BAD_DOWNLOAD_RESUME;
61+
return ErrorCode::BAD_DOWNLOAD_RESUME;
6162
case CURLE_FILE_COULDNT_READ_FILE:
62-
return ErrorCode::FILE_COULDNT_READ_FILE;
63+
return ErrorCode::FILE_COULDNT_READ_FILE;
6364
case CURLE_FUNCTION_NOT_FOUND:
64-
return ErrorCode::FUNCTION_NOT_FOUND;
65+
return ErrorCode::FUNCTION_NOT_FOUND;
6566
case CURLE_ABORTED_BY_CALLBACK:
66-
return ErrorCode::ABORTED_BY_CALLBACK;
67+
return ErrorCode::ABORTED_BY_CALLBACK;
6768
case CURLE_BAD_FUNCTION_ARGUMENT:
68-
return ErrorCode::BAD_FUNCTION_ARGUMENT;
69+
return ErrorCode::BAD_FUNCTION_ARGUMENT;
6970
case CURLE_INTERFACE_FAILED:
70-
return ErrorCode::INTERFACE_FAILED;
71+
return ErrorCode::INTERFACE_FAILED;
7172
case CURLE_TOO_MANY_REDIRECTS:
72-
return ErrorCode::TOO_MANY_REDIRECTS;
73+
return ErrorCode::TOO_MANY_REDIRECTS;
7374
case CURLE_UNKNOWN_OPTION:
74-
return ErrorCode::UNKNOWN_OPTION;
75+
return ErrorCode::UNKNOWN_OPTION;
76+
7577
// Added in curl 7.78.0.
7678
#if LIBCURL_VERSION_NUM >= 0x074E00
7779
case CURLE_SETOPT_OPTION_SYNTAX:
78-
return ErrorCode::SETOPT_OPTION_SYNTAX;
80+
return ErrorCode::SETOPT_OPTION_SYNTAX;
7981
#endif
82+
8083
case CURLE_GOT_NOTHING:
81-
return ErrorCode::GOT_NOTHING;
84+
return ErrorCode::GOT_NOTHING;
8285
case CURLE_SSL_ENGINE_NOTFOUND:
83-
return ErrorCode::SSL_ENGINE_NOTFOUND;
86+
return ErrorCode::SSL_ENGINE_NOTFOUND;
8487
case CURLE_SSL_ENGINE_SETFAILED:
85-
return ErrorCode::SSL_ENGINE_SETFAILED;
88+
return ErrorCode::SSL_ENGINE_SETFAILED;
8689
case CURLE_SEND_ERROR:
87-
return ErrorCode::SEND_ERROR;
90+
return ErrorCode::SEND_ERROR;
8891
case CURLE_RECV_ERROR:
89-
return ErrorCode::RECV_ERROR;
92+
return ErrorCode::RECV_ERROR;
9093
case CURLE_SSL_CERTPROBLEM:
91-
return ErrorCode::SSL_CERTPROBLEM;
94+
return ErrorCode::SSL_CERTPROBLEM;
9295
case CURLE_SSL_CIPHER:
93-
return ErrorCode::SSL_CIPHER;
96+
return ErrorCode::SSL_CIPHER;
9497
case CURLE_PEER_FAILED_VERIFICATION:
95-
return ErrorCode::PEER_FAILED_VERIFICATION;
98+
return ErrorCode::PEER_FAILED_VERIFICATION;
9699
case CURLE_BAD_CONTENT_ENCODING:
97-
return ErrorCode::BAD_CONTENT_ENCODING;
100+
return ErrorCode::BAD_CONTENT_ENCODING;
98101
case CURLE_FILESIZE_EXCEEDED:
99-
return ErrorCode::FILESIZE_EXCEEDED;
102+
return ErrorCode::FILESIZE_EXCEEDED;
100103
case CURLE_USE_SSL_FAILED:
101-
return ErrorCode::USE_SSL_FAILED;
104+
return ErrorCode::USE_SSL_FAILED;
102105
case CURLE_SEND_FAIL_REWIND:
103-
return ErrorCode::SEND_FAIL_REWIND;
106+
return ErrorCode::SEND_FAIL_REWIND;
104107
case CURLE_SSL_ENGINE_INITFAILED:
105-
return ErrorCode::SSL_ENGINE_INITFAILED;
108+
return ErrorCode::SSL_ENGINE_INITFAILED;
106109

107110
// Added in curl 7.13.1.
108111
#if LIBCURL_VERSION_NUM >= 0x070D01
109112
case CURLE_LOGIN_DENIED:
110-
return ErrorCode::LOGIN_DENIED;
113+
return ErrorCode::LOGIN_DENIED;
111114
#endif
112115

113116
// Added in curl 7.16.0.
114117
#if LIBCURL_VERSION_NUM >= 0x071000
115118
case CURLE_SSL_CACERT_BADFILE:
116-
return ErrorCode::SSL_CACERT_BADFILE;
119+
return ErrorCode::SSL_CACERT_BADFILE;
117120
#endif
118121

119122
// Added in curl 7.16.1.
120123
#if LIBCURL_VERSION_NUM >= 0x071001
121124
case CURLE_SSL_SHUTDOWN_FAILED:
122-
return ErrorCode::SSL_SHUTDOWN_FAILED;
125+
return ErrorCode::SSL_SHUTDOWN_FAILED;
123126
#endif
124127

125128
// Added in curl 7.18.2.
126129
#if LIBCURL_VERSION_NUM >= 0x071202
127130
case CURLE_AGAIN:
128-
return ErrorCode::AGAIN;
131+
return ErrorCode::AGAIN;
129132
#endif
130133

131134
// Added in curl 7.19.0.
132135
#if LIBCURL_VERSION_NUM >= 0x071300
133136
case CURLE_SSL_CRL_BADFILE:
134-
return ErrorCode::SSL_CRL_BADFILE;
137+
return ErrorCode::SSL_CRL_BADFILE;
135138
case CURLE_SSL_ISSUER_ERROR:
136-
return ErrorCode::SSL_ISSUER_ERROR;
139+
return ErrorCode::SSL_ISSUER_ERROR;
137140
#endif
138141

139142
// Added in curl 7.21.0.
140143
#if LIBCURL_VERSION_NUM >= 0x071500
141144
case CURLE_CHUNK_FAILED:
142-
return ErrorCode::CHUNK_FAILED;
145+
return ErrorCode::CHUNK_FAILED;
143146
#endif
144147

145148
// Added in curl 7.30.0.
146149
#if LIBCURL_VERSION_NUM >= 0x071E00
147150
case CURLE_NO_CONNECTION_AVAILABLE:
148-
return ErrorCode::NO_CONNECTION_AVAILABLE;
151+
return ErrorCode::NO_CONNECTION_AVAILABLE;
149152
#endif
150153

151154
// Added in curl 7.39.0.
152155
#if LIBCURL_VERSION_NUM >= 0x072700
153156
case CURLE_SSL_PINNEDPUBKEYNOTMATCH:
154-
return ErrorCode::SSL_PINNEDPUBKEYNOTMATCH;
157+
return ErrorCode::SSL_PINNEDPUBKEYNOTMATCH;
155158
#endif
156159

157160
// Added in curl 7.41.0.
158161
#if LIBCURL_VERSION_NUM >= 0x072900
159162
case CURLE_SSL_INVALIDCERTSTATUS:
160-
return ErrorCode::SSL_INVALIDCERTSTATUS;
163+
return ErrorCode::SSL_INVALIDCERTSTATUS;
161164
#endif
162165

163166
// Added in curl 7.49.0.
164167
#if LIBCURL_VERSION_NUM >= 0x073100
165168
case CURLE_HTTP2_STREAM:
166-
return ErrorCode::HTTP2_STREAM;
169+
return ErrorCode::HTTP2_STREAM;
167170
#endif
168171
case CURLE_PARTIAL_FILE:
169-
return ErrorCode::PARTIAL_FILE;
172+
return ErrorCode::PARTIAL_FILE;
170173

171174
// Added in curl 7.59.0.
172175
#if LIBCURL_VERSION_NUM >= 0x073B00
173176
case CURLE_RECURSIVE_API_CALL:
174-
return ErrorCode::RECURSIVE_API_CALL;
177+
return ErrorCode::RECURSIVE_API_CALL;
175178
#endif
176179

177180
// Added in curl 7.66.0.
178181
#if LIBCURL_VERSION_NUM >= 0x074200
179182
case CURLE_AUTH_ERROR:
180-
return ErrorCode::AUTH_ERROR;
183+
return ErrorCode::AUTH_ERROR;
181184
#endif
182185

183186
// Added in curl 7.68.0.
184187
#if LIBCURL_VERSION_NUM >= 0x074400
185188
case CURLE_HTTP3:
186-
return ErrorCode::HTTP3;
189+
return ErrorCode::HTTP3;
187190
#endif
188191

189192
// Added in curl 7.69.0.
190193
#if LIBCURL_VERSION_NUM >= 0x074500
191194
case CURLE_QUIC_CONNECT_ERROR:
192-
return ErrorCode::QUIC_CONNECT_ERROR;
195+
return ErrorCode::QUIC_CONNECT_ERROR;
193196
#endif
194197

195198
// Added in curl 7.73.0.
196199
#if LIBCURL_VERSION_NUM >= 0x074900
197200
case CURLE_PROXY:
198-
return ErrorCode::PROXY;
201+
return ErrorCode::PROXY;
199202
#endif
200203

201204
// Added in curl 7.77.0.
202205
#if LIBCURL_VERSION_NUM >= 0x074D00
203206
case CURLE_SSL_CLIENTCERT:
204-
return ErrorCode::SSL_CLIENTCERT;
207+
return ErrorCode::SSL_CLIENTCERT;
205208
#endif
206209

207210
// Added in curl 7.84.0.
208211
#if LIBCURL_VERSION_NUM >= 0x075400
209212
case CURLE_UNRECOVERABLE_POLL:
210-
return ErrorCode::UNRECOVERABLE_POLL;
213+
return ErrorCode::UNRECOVERABLE_POLL;
211214
#endif
212215

213216
// Added in curl 7.6.0.
214217
#if LIBCURL_VERSION_NUM >= 0x080600
215218
case CURLE_TOO_LARGE:
216-
return ErrorCode::TOO_LARGE;
219+
return ErrorCode::TOO_LARGE;
217220
#endif
218221
default:
219-
return ErrorCode::UNKNOWN_ERROR;
220-
}
222+
return ErrorCode::UNKNOWN_ERROR;
223+
}
221224
}
222-
225+
// NOLINTEND(bugprone-branch-clone)
223226
} // namespace cpr

0 commit comments

Comments
 (0)