Skip to content

Commit 32ac41b

Browse files
committed
Merge pull request #1175 from libcpr/feature/ci-fixes
Clang-Tidy And cppcheck Fixes
1 parent 9eade01 commit 32ac41b

File tree

12 files changed

+72
-40
lines changed

12 files changed

+72
-40
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
@@ -7,27 +7,27 @@
77
#include <string>
88

99
namespace cpr {
10-
const std::string Cookie::GetDomain() const {
10+
const std::string& Cookie::GetDomain() const {
1111
return domain_;
1212
}
1313

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

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

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

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

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

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

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

52-
const std::string Cookies::GetEncoded(const CurlHolder& holder) const {
52+
std::string Cookies::GetEncoded(const CurlHolder& holder) const {
5353
std::stringstream stream;
5454
for (const cpr::Cookie& item : cookies_) {
5555
// 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
EncodedAuthentication::~EncodedAuthentication() noexcept {

cpr/session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void Session::SetBody(Body&& body) {
439439

440440
void Session::SetLowSpeed(const LowSpeed& low_speed) {
441441
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_LIMIT, low_speed.limit);
442-
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time);
442+
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time); // cppcheck-suppress y2038-unsafe-call
443443
}
444444

445445
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: 1 addition & 0 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>

0 commit comments

Comments
 (0)