diff --git a/.clang-tidy b/.clang-tidy
index b444e2e18..0db89ae0e 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -40,5 +40,5 @@ Checks: '*,
-boost-use-ranges
'
WarningsAsErrors: '*'
-HeaderFilterRegex: 'src/*.hpp'
+HeaderFilterRegex: 'src\/*.hpp'
FormatStyle: file
diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml
index 7bb0fad92..d3d674fa7 100644
--- a/.github/workflows/cppcheck.yml
+++ b/.github/workflows/cppcheck.yml
@@ -17,6 +17,8 @@ jobs:
- name: "[Release g++] Build"
env:
CPR_ENABLE_CPPCHECK: ON
+ # Avoid parallel runs so only the resulting error file is not being written by multiple processes at the same time.
+ CMAKE_BUILD_PARALLEL_LEVEL: 1
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{github.workspace}}/build
diff --git a/CppCheckSuppressions.txt b/CppCheckSuppressions.txt
deleted file mode 100644
index fec131b11..000000000
--- a/CppCheckSuppressions.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-noExplicitConstructor
-ConfigurationNotChecked
-passedByValue
diff --git a/cmake/cppcheck.cmake b/cmake/cppcheck.cmake
index 8ef468806..9ed9ab014 100644
--- a/cmake/cppcheck.cmake
+++ b/cmake/cppcheck.cmake
@@ -1,10 +1,15 @@
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
+
if(CMAKE_CXX_CPPCHECK)
- list(APPEND CMAKE_CXX_CPPCHECK
+ list(APPEND CMAKE_CXX_CPPCHECK "--xml"
"--error-exitcode=1"
"--enable=warning,style"
- "--force"
+ "--force"
"--inline-suppr"
+ "--addon=y2038"
"--std=c++${CMAKE_CXX_STANDARD}"
- "--suppressions-list=${CMAKE_SOURCE_DIR}/CppCheckSuppressions.txt")
+ "--cppcheck-build-dir=${PROJECT_BINARY_DIR}"
+ "--suppress-xml=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.xml"
+ "--output-file=${PROJECT_BINARY_DIR}/cppcheck.xml"
+ "--check-level=normal")
endif()
diff --git a/cppcheck-suppressions.xml b/cppcheck-suppressions.xml
new file mode 100644
index 000000000..7e9054e98
--- /dev/null
+++ b/cppcheck-suppressions.xml
@@ -0,0 +1,37 @@
+
+
+
+
+ *
+ */build/*
+
+
+ CheckLevelMaxBranches
+
+
+ noExplicitConstructor
+
+
+ knownConditionTrueFalse
+ */include/cpr/async_wrapper.h
+
+
+ y2038-unsafe-call
+ */cpr/cookies.cpp
+
+
+
+ y2038-unsafe-call
+ */include/cpr/low_speed.h
+
+
+ normalCheckLevelMaxBranches
+
+
+ constParameterPointer
+ */cpr/util.cpp
+
+
+ postfixOperator
+
+
\ No newline at end of file
diff --git a/cpr/cookies.cpp b/cpr/cookies.cpp
index f031fe72d..a79d8c7d7 100644
--- a/cpr/cookies.cpp
+++ b/cpr/cookies.cpp
@@ -8,7 +8,7 @@
#include
namespace cpr {
-const std::string Cookie::GetDomain() const {
+const std::string& Cookie::GetDomain() const {
return domain_;
}
@@ -16,7 +16,7 @@ bool Cookie::IsIncludingSubdomains() const {
return includeSubdomains_;
}
-const std::string Cookie::GetPath() const {
+const std::string& Cookie::GetPath() const {
return path_;
}
@@ -24,11 +24,11 @@ bool Cookie::IsHttpsOnly() const {
return httpsOnly_;
}
-const std::chrono::system_clock::time_point Cookie::GetExpires() const {
+std::chrono::system_clock::time_point Cookie::GetExpires() const {
return expires_;
}
-const std::string Cookie::GetExpiresString() const {
+std::string Cookie::GetExpiresString() const {
std::stringstream ss;
std::tm tm{};
const std::time_t tt = std::chrono::system_clock::to_time_t(expires_);
@@ -42,15 +42,15 @@ const std::string Cookie::GetExpiresString() const {
return ss.str();
}
-const std::string Cookie::GetName() const {
+const std::string& Cookie::GetName() const {
return name_;
}
-const std::string Cookie::GetValue() const {
+const std::string& Cookie::GetValue() const {
return value_;
}
-const std::string Cookies::GetEncoded(const CurlHolder& holder) const {
+std::string Cookies::GetEncoded(const CurlHolder& holder) const {
std::stringstream stream;
for (const cpr::Cookie& item : cookies_) {
// Depending on if encoding is set to "true", we will URL-encode cookies
diff --git a/cpr/proxyauth.cpp b/cpr/proxyauth.cpp
index fc7b80d28..b6802bffa 100644
--- a/cpr/proxyauth.cpp
+++ b/cpr/proxyauth.cpp
@@ -1,6 +1,6 @@
#include "cpr/proxyauth.h"
-#include "cpr/util.h"
#include
+#include
namespace cpr {
diff --git a/cpr/session.cpp b/cpr/session.cpp
index 5a42ddc15..bc06e1e7e 100644
--- a/cpr/session.cpp
+++ b/cpr/session.cpp
@@ -184,8 +184,8 @@ void Session::prepareCommonShared() {
// handle NO_PROXY override passed through Proxies object
// Example: Proxies{"no_proxy": ""} will override environment variable definition with an empty list
const std::array no_proxy{"no_proxy", "NO_PROXY"};
- for (const auto& item : no_proxy) {
- if (proxies_.has(item)) {
+ for (const auto& item : no_proxy) { // cppcheck-suppress useStlAlgorithm
+ if (proxies_.has(item)) { // cppcheck-suppress useStlAlgorithm
curl_easy_setopt(curl_->handle, CURLOPT_NOPROXY, proxies_[item].c_str());
break;
}
@@ -449,7 +449,7 @@ void Session::SetBody(Body&& body) {
void Session::SetLowSpeed(const LowSpeed& low_speed) {
curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_LIMIT, low_speed.limit);
- curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time);
+ curl_easy_setopt(curl_->handle, CURLOPT_LOW_SPEED_TIME, low_speed.time); // cppcheck-suppress y2038-unsafe-call
}
void Session::SetVerifySsl(const VerifySsl& verify) {
diff --git a/cpr/threadpool.cpp b/cpr/threadpool.cpp
index ff4317037..36b6400da 100644
--- a/cpr/threadpool.cpp
+++ b/cpr/threadpool.cpp
@@ -111,9 +111,7 @@ bool ThreadPool::CreateThread() {
if (task) {
task();
++idle_thread_num;
- if (initialRun) {
- initialRun = false;
- }
+ initialRun = false;
}
}
});
diff --git a/cpr/util.cpp b/cpr/util.cpp
index 818b80b65..c101ce619 100644
--- a/cpr/util.cpp
+++ b/cpr/util.cpp
@@ -3,6 +3,7 @@
#include "cpr/cookies.h"
#include "cpr/cprtypes.h"
#include "cpr/curlholder.h"
+#include "cpr/secure_string.h"
#include
#include
#include
@@ -11,7 +12,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -189,8 +189,7 @@ util::SecureString urlDecode(std::string_view s) {
bool isTrue(const std::string& s) {
constexpr std::string_view tmp = "true";
- 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; });
+ 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; });
return s_it == s.end() && tmp_it == tmp.end();
}
diff --git a/include/cpr/cookies.h b/include/cpr/cookies.h
index 60f421bc4..052d9a8c0 100644
--- a/include/cpr/cookies.h
+++ b/include/cpr/cookies.h
@@ -4,7 +4,6 @@
#include "cpr/curlholder.h"
#include
#include
-#include
#include
#include
@@ -24,14 +23,14 @@ class Cookie {
* So we fall back to std::chrono::system_clock::from_time_t(0) for the minimum value here.
**/
Cookie(const std::string& name, const std::string& value, const std::string& domain = "", bool p_isIncludingSubdomains = false, const std::string& path = "/", bool p_isHttpsOnly = false, std::chrono::system_clock::time_point expires = std::chrono::system_clock::from_time_t(0)) : name_{name}, value_{value}, domain_{domain}, includeSubdomains_{p_isIncludingSubdomains}, path_{path}, httpsOnly_{p_isHttpsOnly}, expires_{expires} {}
- const std::string GetDomain() const;
- bool IsIncludingSubdomains() const;
- const std::string GetPath() const;
- bool IsHttpsOnly() const;
- const std::chrono::system_clock::time_point GetExpires() const;
- const std::string GetExpiresString() const;
- const std::string GetName() const;
- const std::string GetValue() const;
+ [[nodiscard]] const std::string& GetDomain() const;
+ [[nodiscard]] bool IsIncludingSubdomains() const;
+ [[nodiscard]] const std::string& GetPath() const;
+ [[nodiscard]] bool IsHttpsOnly() const;
+ [[nodiscard]] std::chrono::system_clock::time_point GetExpires() const;
+ [[nodiscard]] std::string GetExpiresString() const;
+ [[nodiscard]] const std::string& GetName() const;
+ [[nodiscard]] const std::string& GetValue() const;
private:
std::string name_;
@@ -68,17 +67,17 @@ class Cookies {
Cookies(const cpr::Cookie& cookie, bool p_encode = true) : encode{p_encode}, cookies_{cookie} {}
cpr::Cookie& operator[](size_t pos);
- const std::string GetEncoded(const CurlHolder& holder) const;
+ [[nodiscard]] std::string GetEncoded(const CurlHolder& holder) const;
using iterator = std::vector::iterator;
using const_iterator = std::vector::const_iterator;
iterator begin();
iterator end();
- const_iterator begin() const;
- const_iterator end() const;
- const_iterator cbegin() const;
- const_iterator cend() const;
+ [[nodiscard]] const_iterator begin() const;
+ [[nodiscard]] const_iterator end() const;
+ [[nodiscard]] const_iterator cbegin() const;
+ [[nodiscard]] const_iterator cend() const;
void emplace_back(const Cookie& str);
[[nodiscard]] bool empty() const;
void push_back(const Cookie& str);
diff --git a/test/get_tests.cpp b/test/get_tests.cpp
index 132c2790e..276ea157f 100644
--- a/test/get_tests.cpp
+++ b/test/get_tests.cpp
@@ -15,13 +15,6 @@ using namespace cpr;
static HttpServer* server = new HttpServer();
-TEST(BasicTests, XXXTest) {
- Url url{"https://getsolara.dev/api/endpoint.json"};
- Response response = cpr::Get(url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
-}
-
TEST(BasicTests, HelloWorldTest) {
Url url{server->GetBaseUrl() + "/hello.html"};
Response response = cpr::Get(url);