summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-08-07 13:07:00 +0800
committerluwenpeng <[email protected]>2024-08-12 15:48:31 +0800
commitf1b3928c7093dafb553ef51f49db58659525e502 (patch)
tree9d82b6bfff6053627eed2521d0f6bfe232c44b54
parent526171618ff2e51ac86704095cf218b6e2d86702 (diff)
🔧 build(enable cppcheck on build): eliminate cppcheck error
-rw-r--r--CMakeLists.txt34
-rw-r--r--src/packet/ip4_utils.h2
-rw-r--r--src/packet/packet_parse.cpp10
-rw-r--r--src/session/test/gtest_sess_mgr_tcp_reassembly.cpp2
-rw-r--r--test/packet_inject/packet_inject.cpp2
-rw-r--r--test/packet_tool/packet_tool.cpp5
6 files changed, 42 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cbfdacd..61b786b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,6 +22,40 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "/opt/tsg/stellar" CACHE PATH "default install path" FORCE)
endif()
+find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
+if (CMAKE_CXX_CPPCHECK)
+ list(
+ APPEND CMAKE_CXX_CPPCHECK
+ "--enable=all"
+ "--std=c++11"
+ "--error-exitcode=1"
+ "--suppress=unusedFunction"
+ "--suppress=missingInclude"
+ "--suppress=uselessAssignmentPtrArg"
+ "--suppress=unmatchedSuppression"
+ "--suppress=variableScope"
+ "--suppress=unreadVariable"
+ "--suppress=cstyleCast"
+ "--suppress=memleakOnRealloc"
+ "--suppress=constParameter"
+ "--suppress=uselessAssignmentArg"
+ "--suppress=uninitvar"
+ "--suppress=unusedStructMember"
+ "--suppress=unreachableCode"
+ "--suppress=internalAstError"
+ "--suppress=nullPointerRedundantCheck"
+ "--suppress=ctunullpointer"
+ "--suppress=redundantAssignment"
+ "--suppress=duplicateValueTernary"
+ "--suppress=funcArgOrderDifferent"
+ "--suppress=*:${PROJECT_SOURCE_DIR}/vendors/*"
+ "--suppress=*:${PROJECT_SOURCE_DIR}/deps/*"
+ )
+ set(CMAKE_C_CPPCHECK ${CMAKE_CXX_CPPCHECK})
+else()
+ message(FATAL_ERROR "Could not find the program cppcheck.")
+endif()
+
option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE)
option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE)
diff --git a/src/packet/ip4_utils.h b/src/packet/ip4_utils.h
index fc3ccfa..84c8805 100644
--- a/src/packet/ip4_utils.h
+++ b/src/packet/ip4_utils.h
@@ -253,7 +253,7 @@ static inline void ip4_hdr_set_opt_len(struct ip *hdr, uint8_t opt_len)
// must be called after ip4_hdr_set_opt_len
static inline void ip4_hdr_set_opt_data(struct ip *hdr, const char *opt_data)
{
- memcpy((char *)hdr + sizeof(struct ip), opt_data, ip4_hdr_get_opt_len(hdr));
+ if(opt_data)memcpy((char *)hdr + sizeof(struct ip), opt_data, ip4_hdr_get_opt_len(hdr));
}
/******************************************************************************
diff --git a/src/packet/packet_parse.cpp b/src/packet/packet_parse.cpp
index d40226f..7139c8a 100644
--- a/src/packet/packet_parse.cpp
+++ b/src/packet/packet_parse.cpp
@@ -722,11 +722,11 @@ static inline const char *parse_udp(struct packet *pkt, const char *data, uint16
{
return data;
}
- const struct udphdr *hdr = (struct udphdr *)data;
+ const struct udphdr *udp_hdr = (struct udphdr *)data;
SET_LAYER(pkt, layer, LAYER_PROTO_UDP, sizeof(struct udphdr), data, len, 0);
- uint16_t src_port = udp_hdr_get_src_port(hdr);
- uint16_t dst_port = udp_hdr_get_dst_port(hdr);
+ uint16_t src_port = udp_hdr_get_src_port(udp_hdr);
+ uint16_t dst_port = udp_hdr_get_dst_port(udp_hdr);
if (dst_port == 4789)
{
@@ -772,8 +772,8 @@ static inline const char *parse_udp(struct packet *pkt, const char *data, uint16
{
return layer->pld_ptr;
}
- const struct ip6_hdr *hdr = (const struct ip6_hdr *)layer->pld_ptr;
- if (ip6_hdr_get_version(hdr) != 6)
+ const struct ip6_hdr *ipv6_hdr = (const struct ip6_hdr *)layer->pld_ptr;
+ if (ip6_hdr_get_version(ipv6_hdr) != 6)
{
return layer->pld_ptr;
}
diff --git a/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp b/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
index 2f4f235..a6a6c32 100644
--- a/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
+++ b/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
@@ -51,7 +51,7 @@ struct session_manager_options opts = {
static void hex_dump(const char *payload, uint32_t len)
{
- printf("Payload Length: %d\n", len);
+ printf("Payload Length: %u\n", len);
for (uint32_t i = 0; i < len; i++)
{
if (i > 0 && i % 16 == 0)
diff --git a/test/packet_inject/packet_inject.cpp b/test/packet_inject/packet_inject.cpp
index 04e8851..3161218 100644
--- a/test/packet_inject/packet_inject.cpp
+++ b/test/packet_inject/packet_inject.cpp
@@ -377,7 +377,7 @@ static void craft_and_send_tcp_packet(struct stellar *st, struct session *sess,
else
{
tcp_seq = uint32_add(pkt_exdata->tcp_ack, pkt_exdata->inc_ack);
- tcp_ack = uint32_add(pkt_exdata->tcp_seq, pkt_exdata->tcp_payload_len + (pkt_exdata->tcp_flags & TH_SYN ? 1 : 0));
+ tcp_ack = uint32_add(pkt_exdata->tcp_seq, pkt_exdata->tcp_payload_len + ((pkt_exdata->tcp_flags & TH_SYN) ? 1 : 0));
pkt_exdata->inc_ack += tcp_payload_len;
pkt_exdata->inc_ack += (tcp_flags & TH_FIN) ? 1 : 0; // inject RST packer after FIN packer, ack should be increased by 1
diff --git a/test/packet_tool/packet_tool.cpp b/test/packet_tool/packet_tool.cpp
index 67c1f31..cd5af41 100644
--- a/test/packet_tool/packet_tool.cpp
+++ b/test/packet_tool/packet_tool.cpp
@@ -279,13 +279,8 @@ static void usage(char *cmd)
int main(int argc, char **argv)
{
int opt = 0;
-<<<<<<< HEAD
struct runtime rte = {0};
while ((opt = getopt(argc, argv, "f:tvh")) != -1)
-=======
- struct runtime rte = {};
- while ((opt = getopt(argc, argv, "f:tvch")) != -1)
->>>>>>> 654eee3 (🔧 build(compile Werror): reduce warning)
{
switch (opt)
{