🔧 build(enable cppcheck on build): eliminate cppcheck error
This commit is contained in:
@@ -22,6 +22,40 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|||||||
set (CMAKE_INSTALL_PREFIX "/opt/tsg/stellar" CACHE PATH "default install path" FORCE)
|
set (CMAKE_INSTALL_PREFIX "/opt/tsg/stellar" CACHE PATH "default install path" FORCE)
|
||||||
endif()
|
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_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)
|
option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// must be called after ip4_hdr_set_opt_len
|
||||||
static inline void ip4_hdr_set_opt_data(struct ip *hdr, const char *opt_data)
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
|||||||
@@ -722,11 +722,11 @@ static inline const char *parse_udp(struct packet *pkt, const char *data, uint16
|
|||||||
{
|
{
|
||||||
return data;
|
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);
|
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 src_port = udp_hdr_get_src_port(udp_hdr);
|
||||||
uint16_t dst_port = udp_hdr_get_dst_port(hdr);
|
uint16_t dst_port = udp_hdr_get_dst_port(udp_hdr);
|
||||||
|
|
||||||
if (dst_port == 4789)
|
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;
|
return layer->pld_ptr;
|
||||||
}
|
}
|
||||||
const struct ip6_hdr *hdr = (const struct ip6_hdr *)layer->pld_ptr;
|
const struct ip6_hdr *ipv6_hdr = (const struct ip6_hdr *)layer->pld_ptr;
|
||||||
if (ip6_hdr_get_version(hdr) != 6)
|
if (ip6_hdr_get_version(ipv6_hdr) != 6)
|
||||||
{
|
{
|
||||||
return layer->pld_ptr;
|
return layer->pld_ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct session_manager_options opts = {
|
|||||||
|
|
||||||
static void hex_dump(const char *payload, uint32_t len)
|
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++)
|
for (uint32_t i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i > 0 && i % 16 == 0)
|
if (i > 0 && i % 16 == 0)
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ static void craft_and_send_tcp_packet(struct stellar *st, struct session *sess,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
tcp_seq = uint32_add(pkt_exdata->tcp_ack, pkt_exdata->inc_ack);
|
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_payload_len;
|
||||||
pkt_exdata->inc_ack += (tcp_flags & TH_FIN) ? 1 : 0; // inject RST packer after FIN packer, ack should be increased by 1
|
pkt_exdata->inc_ack += (tcp_flags & TH_FIN) ? 1 : 0; // inject RST packer after FIN packer, ack should be increased by 1
|
||||||
|
|||||||
@@ -279,13 +279,8 @@ static void usage(char *cmd)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
<<<<<<< HEAD
|
|
||||||
struct runtime rte = {0};
|
struct runtime rte = {0};
|
||||||
while ((opt = getopt(argc, argv, "f:tvh")) != -1)
|
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)
|
switch (opt)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user