Skip to content

Commit c8a803c

Browse files
authored
Merge pull request #1175 from libcpr/feature/ci-fixes
Clang-Tidy And cppcheck Fixes
2 parents 4c41606 + cfb7960 commit c8a803c

File tree

12 files changed

+75
-45
lines changed

12 files changed

+75
-45
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ Checks: '*,
4040
-boost-use-ranges
4141
'
4242
WarningsAsErrors: '*'
43-
HeaderFilterRegex: 'src/*.hpp'
43+
HeaderFilterRegex: 'src\/*.hpp'
4444
FormatStyle: file

.github/workflows/cppcheck.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
- name: "[Release g++] Build"
1818
env:
1919
CPR_ENABLE_CPPCHECK: ON
20+
# Avoid parallel runs so only the resulting error file is not being written by multiple processes at the same time.
21+
CMAKE_BUILD_PARALLEL_LEVEL: 1
2022
uses: ashutoshvarma/action-cmake-build@master
2123
with:
2224
build-dir: ${{github.workspace}}/build

CppCheckSuppressions.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmake/cppcheck.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
2+
23
if(CMAKE_CXX_CPPCHECK)
3-
list(APPEND CMAKE_CXX_CPPCHECK
4+
list(APPEND CMAKE_CXX_CPPCHECK "--xml"
45
"--error-exitcode=1"
56
"--enable=warning,style"
6-
"--force"
7+
"--force"
78
"--inline-suppr"
9+
"--addon=y2038"
810
"--std=c++${CMAKE_CXX_STANDARD}"
9-
"--suppressions-list=${CMAKE_SOURCE_DIR}/CppCheckSuppressions.txt")
11+
"--cppcheck-build-dir=${PROJECT_BINARY_DIR}"
12+
"--suppress-xml=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.xml"
13+
"--output-file=${PROJECT_BINARY_DIR}/cppcheck.xml"
14+
"--check-level=normal")
1015
endif()

cppcheck-suppressions.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0"?>
2+
<suppressions>
3+
<!-- Exclude Paths -->
4+
<suppress>
5+
<id>*</id>
6+
<fileName>*/build/*</fileName>
7+
</suppress>
8+
<suppress>
9+
<id>CheckLevelMaxBranches</id>
10+
</suppress>
11+
<suppress>
12+
<id>noExplicitConstructor</id>
13+
</suppress>
14+
<suppress>
15+
<id>knownConditionTrueFalse</id>
16+
<fileName>*/include/cpr/async_wrapper.h</fileName>
17+
</suppress>
18+
<suppress>
19+
<id>y2038-unsafe-call</id>
20+
<fileName>*/cpr/cookies.cpp</fileName>
21+
</suppress>
22+
<!-- Known Limitation/Bug: https://github.com/libcpr/cpr/issues/1174 -->
23+
<suppress>
24+
<id>y2038-unsafe-call</id>
25+
<fileName>*/include/cpr/low_speed.h</fileName>
26+
</suppress>
27+
<suppress>
28+
<id>normalCheckLevelMaxBranches</id>
29+
</suppress>
30+
<suppress>
31+
<id>constParameterPointer</id>
32+
<fileName>*/cpr/util.cpp</fileName>
33+
</suppress>
34+
<suppress>
35+
<id>postfixOperator</id>
36+
</suppress>
37+
</suppressions>

cpr/cookies.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
#include <string_view>
99

1010
namespace cpr {
11-
const std::string Cookie::GetDomain() const {
11+
const std::string& Cookie::GetDomain() const {
1212
return domain_;
1313
}
1414

1515
bool Cookie::IsIncludingSubdomains() const {
1616
return includeSubdomains_;
1717
}
1818

19-
const std::string Cookie::GetPath() const {
19+
const std::string& Cookie::GetPath() const {
2020
return path_;
2121
}
2222

2323
bool Cookie::IsHttpsOnly() const {
2424
return httpsOnly_;
2525
}
2626

27-
const std::chrono::system_clock::time_point Cookie::GetExpires() const {
27+
std::chrono::system_clock::time_point Cookie::GetExpires() const {
2828
return expires_;
2929
}
3030

31-
const std::string Cookie::GetExpiresString() const {
31+
std::string Cookie::GetExpiresString() const {
3232
std::stringstream ss;
3333
std::tm tm{};
3434
const std::time_t tt = std::chrono::system_clock::to_time_t(expires_);
@@ -42,15 +42,15 @@ const std::string Cookie::GetExpiresString() const {
4242
return ss.str();
4343
}
4444

45-
const std::string Cookie::GetName() const {
45+
const std::string& Cookie::GetName() const {
4646
return name_;
4747
}
4848

49-
const std::string Cookie::GetValue() const {
49+
const std::string& Cookie::GetValue() const {
5050
return value_;
5151
}
5252

53-
const std::string Cookies::GetEncoded(const CurlHolder& holder) const {
53+
std::string Cookies::GetEncoded(const CurlHolder& holder) const {
5454
std::stringstream stream;
5555
for (const cpr::Cookie& item : cookies_) {
5656
// Depending on if encoding is set to "true", we will URL-encode cookies

cpr/proxyauth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cpr/proxyauth.h"
2-
#include "cpr/util.h"
32
#include <string>
3+
#include <string_view>
44

55
namespace cpr {
66

cpr/session.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ void Session::prepareCommonShared() {
184184
// handle NO_PROXY override passed through Proxies object
185185
// Example: Proxies{"no_proxy": ""} will override environment variable definition with an empty list
186186
const std::array<std::string, 2> no_proxy{"no_proxy", "NO_PROXY"};
187-
for (const auto& item : no_proxy) {
188-
if (proxies_.has(item)) {
187+
for (const auto& item : no_proxy) { // cppcheck-suppress useStlAlgorithm
188+
if (proxies_.has(item)) { // cppcheck-suppress useStlAlgorithm
189189
curl_easy_setopt(curl_->handle, CURLOPT_NOPROXY, proxies_[item].c_str());
190190
break;
191191
}
@@ -449,7 +449,7 @@ void Session::SetBody(Body&& body) {
449449

450450
void Session::SetLowSpeed(const LowSpeed& low_speed) {
451451
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_LIMIT, low_speed.limit);
452-
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time);
452+
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time); // cppcheck-suppress y2038-unsafe-call
453453
}
454454

455455
void Session::SetVerifySsl(const VerifySsl& verify) {

cpr/threadpool.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ bool ThreadPool::CreateThread() {
111111
if (task) {
112112
task();
113113
++idle_thread_num;
114-
if (initialRun) {
115-
initialRun = false;
116-
}
114+
initialRun = false;
117115
}
118116
}
119117
});

cpr/util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "cpr/cookies.h"
44
#include "cpr/cprtypes.h"
55
#include "cpr/curlholder.h"
6+
#include "cpr/secure_string.h"
67
#include <algorithm>
78
#include <cctype>
89
#include <chrono>
@@ -11,7 +12,6 @@
1112
#include <curl/curl.h>
1213
#include <fstream>
1314
#include <ios>
14-
#include <iterator>
1515
#include <sstream>
1616
#include <string>
1717
#include <type_traits>
@@ -189,8 +189,7 @@ util::SecureString urlDecode(std::string_view s) {
189189

190190
bool isTrue(const std::string& s) {
191191
constexpr std::string_view tmp = "true";
192-
auto [s_it, tmp_it] = std::mismatch(s.begin(), s.end(), tmp.begin(), tmp.end(),
193-
[](auto s_c, auto t_c) { return std::tolower(s_c) == t_c; });
192+
auto [s_it, tmp_it] = std::mismatch(s.begin(), s.end(), tmp.begin(), tmp.end(), [](auto s_c, auto t_c) { return std::tolower(s_c) == t_c; });
194193
return s_it == s.end() && tmp_it == tmp.end();
195194
}
196195

0 commit comments

Comments
 (0)