🔧 build(enable cppcheck on build): eliminate cppcheck error

This commit is contained in:
yangwei
2024-08-07 13:07:00 +08:00
committed by luwenpeng
parent 526171618f
commit f1b3928c70
6 changed files with 42 additions and 13 deletions

View File

@@ -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)

View File

@@ -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));
}
/******************************************************************************

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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)
{