Skip to content

Commit ae53922

Browse files
committed
Clang Tidy path hint while searching for program.
Cppcheck path hint while searching for program. Fixups/suppressions for clang-tidy checks. Suppressions for cppcheck-s.
1 parent 455d2bc commit ae53922

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

cmake/clang-tidy.cmake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
# Include this file if and only if you want to use clang-tidy linter.
2+
13
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
2-
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
4+
if (NOT ${CPR_LINTER_PATH} STREQUAL "")
5+
get_filename_component(CLANG_TIDY_HINT_FILENAME ${CPR_LINTER_PATH} NAME)
6+
get_filename_component(CLANG_TIDY_HINT_PATH ${CPR_LINTER_PATH} DIRECTORY)
7+
endif ()
8+
9+
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy ${CLANG_TIDY_HINT_FILENAME} HINTS ${CLANG_TIDY_HINT_PATH} REQUIRED)
310
mark_as_advanced(CLANG_TIDY_EXECUTABLE)
411

5-
if (${CLANG_TIDY_EXECUTABLE})
6-
message(FATAL_ERROR "Clang-tidy not found")
7-
else()
8-
message(STATUS "Enabling clang-tidy")
9-
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};-warnings-as-errors=*")
10-
endif()
11-
else()
12+
message(STATUS "Enabling clang-tidy: ${CLANG_TIDY_EXECUTABLE}")
13+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};-warnings-as-errors=*")
14+
else ()
1215
message(FATAL_ERROR "Clang-tidy is not supported when building for windows")
13-
endif()
16+
endif ()

cmake/cppcheck.cmake

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
1+
# Include this file if and only if you want to use cppcheck.
22

3-
if(CMAKE_CXX_CPPCHECK)
4-
list(APPEND CMAKE_CXX_CPPCHECK "--xml"
3+
if (NOT ${CPR_CPPCHECK_PATH} STREQUAL "")
4+
get_filename_component(CPPCHECK_HINT_FILENAME ${CPR_CPPCHECK_PATH} NAME)
5+
get_filename_component(CPPCHECK_HINT_PATH ${CPR_CPPCHECK_PATH} DIRECTORY)
6+
endif ()
7+
8+
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck ${CPPCHECK_HINT_FILENAME} HINTS ${CPPCHECK_HINT_PATH} REQUIRED)
9+
message(STATUS "Found cppcheck: ${CMAKE_CXX_CPPCHECK}")
10+
11+
list(APPEND CMAKE_CXX_CPPCHECK
12+
"--xml"
513
"--error-exitcode=1"
614
"--enable=warning,style"
715
"--force"
@@ -11,5 +19,5 @@ if(CMAKE_CXX_CPPCHECK)
1119
"--cppcheck-build-dir=${PROJECT_BINARY_DIR}"
1220
"--suppress-xml=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.xml"
1321
"--output-file=${PROJECT_BINARY_DIR}/cppcheck.xml"
14-
"--check-level=normal")
15-
endif()
22+
"--check-level=normal"
23+
)

cppcheck-suppressions.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<id>y2038-unsafe-call</id>
2525
<fileName>*/include/cpr/low_speed.h</fileName>
2626
</suppress>
27+
<!-- No reason to check third party includes -->
28+
<suppress>
29+
<id>y2038-unsafe-call</id>
30+
<fileName>*/curl/curl.h</fileName>
31+
</suppress>
2732
<suppress>
2833
<id>normalCheckLevelMaxBranches</id>
2934
</suppress>

cpr/session.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <optional>
1313
#include <stdexcept>
1414
#include <string>
15+
#include <string_view>
16+
#include <type_traits>
1517
#include <utility>
1618
#include <variant>
1719
#include <vector>
@@ -26,6 +28,7 @@
2628
#include "cpr/auth.h"
2729
#include "cpr/bearer.h"
2830
#include "cpr/body.h"
31+
#include "cpr/body_view.h"
2932
#include "cpr/callback.h"
3033
#include "cpr/connect_timeout.h"
3134
#include "cpr/cookies.h"
@@ -492,6 +495,7 @@ void Session::SetBody(Body&& body) {
492495
content_ = std::move(body);
493496
}
494497

498+
// cppcheck-suppress passedByValue
495499
void Session::SetBodyView(BodyView body) {
496500
static_assert(std::is_trivially_copyable_v<BodyView>, "BodyView expected to be trivially copyable otherwise will need some std::move across codebase");
497501
content_ = body;
@@ -983,6 +987,7 @@ void Session::prepareBodyPayloadOrMultipart() const {
983987
} else if (std::holds_alternative<cpr::BodyView>(content_)) {
984988
const std::string_view body = std::get<cpr::BodyView>(content_).str();
985989
curl_easy_setopt(curl_->handle, CURLOPT_POSTFIELDSIZE_LARGE, static_cast<curl_off_t>(body.length()));
990+
// NOLINTNEXTLINE (bugprone-suspicious-stringview-data-usage)
986991
curl_easy_setopt(curl_->handle, CURLOPT_POSTFIELDS, body.data());
987992
} else if (std::holds_alternative<cpr::Multipart>(content_)) {
988993
// Make sure, we have a empty multipart to start with:
@@ -1070,6 +1075,7 @@ void Session::SetOption(const Redirect& redirect) { SetRedirect(redirect); }
10701075
void Session::SetOption(const Cookies& cookies) { SetCookies(cookies); }
10711076
void Session::SetOption(const Body& body) { SetBody(body); }
10721077
void Session::SetOption(Body&& body) { SetBody(std::move(body)); }
1078+
// cppcheck-suppress passedByValue
10731079
void Session::SetOption(BodyView body) { SetBodyView(body); }
10741080
void Session::SetOption(const LowSpeed& low_speed) { SetLowSpeed(low_speed); }
10751081
void Session::SetOption(const VerifySsl& verify) { SetVerifySsl(verify); }

0 commit comments

Comments
 (0)