Skip to content

Commit

Permalink
Fixed some SonarCloud issues
Browse files Browse the repository at this point in the history
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
  • Loading branch information
utoni committed Nov 14, 2024
1 parent 9efdecf commit c84c52e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
15 changes: 8 additions & 7 deletions dependencies/nDPIsrvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ static inline int nDPIsrvd_setup_address(struct nDPIsrvd_address * const address
{
address->raw.sa_family = AF_INET;
address->size = sizeof(address->in);
address->in.sin_port = htons(atoi(last_colon + 1));
address->in.sin_port = htons((uint16_t)atoi(last_colon + 1));
sock_addr = &address->in.sin_addr;

if (len < 7)
Expand All @@ -698,7 +698,7 @@ static inline int nDPIsrvd_setup_address(struct nDPIsrvd_address * const address
{
address->raw.sa_family = AF_INET6;
address->size = sizeof(address->in6);
address->in6.sin6_port = htons(atoi(last_colon + 1));
address->in6.sin6_port = htons((uint16_t)atoi(last_colon + 1));
sock_addr = &address->in6.sin6_addr;

if (len < 2)
Expand Down Expand Up @@ -803,7 +803,7 @@ static inline enum nDPIsrvd_conversion_return str_value_to_ull(char const * cons
return CONVERSION_OK;
}

static inline nDPIsrvd_hashkey nDPIsrvd_build_key(char const * str, int len)
static inline nDPIsrvd_hashkey nDPIsrvd_build_key(char const * str, size_t len)
{
uint32_t hash = nDPIsrvd_HASHKEY_SEED;
uint32_t c;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ static inline struct nDPIsrvd_json_token * nDPIsrvd_find_token(struct nDPIsrvd_s

static inline struct nDPIsrvd_json_token * nDPIsrvd_add_token(struct nDPIsrvd_socket * const sock,
nDPIsrvd_hashkey hash_value,
int value_token_index)
size_t value_token_index)
{
struct nDPIsrvd_json_token * token = nDPIsrvd_find_token(sock, hash_value);

Expand All @@ -1125,7 +1125,8 @@ static inline struct nDPIsrvd_json_token * nDPIsrvd_add_token(struct nDPIsrvd_so
static inline int nDPIsrvd_walk_tokens(
struct nDPIsrvd_socket * const sock, nDPIsrvd_hashkey h, size_t b, int count, uint8_t is_value, uint8_t depth)
{
int i, j;
int i;
int j;
jsmntok_t const * key;
jsmntok_t const * const t = &sock->jsmn.tokens[b];
char const * const js = sock->buffer.json_message;
Expand Down Expand Up @@ -1225,7 +1226,7 @@ static inline struct nDPIsrvd_instance * nDPIsrvd_get_instance(struct nDPIsrvd_s
}

static inline struct nDPIsrvd_thread_data * nDPIsrvd_get_thread_data(
struct nDPIsrvd_socket * const sock,
struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_instance * const instance,
struct nDPIsrvd_json_token const * const thread_id_token,
struct nDPIsrvd_json_token const * const ts_usec_token)
Expand All @@ -1241,7 +1242,7 @@ static inline struct nDPIsrvd_thread_data * nDPIsrvd_get_thread_data(
{
nDPIsrvd_ull thread_key;
TOKEN_VALUE_TO_ULL(sock, thread_id_token, &thread_key);
thread_id = thread_key;
thread_id = (nDPIsrvd_hashkey)thread_key;
}

HASH_FIND_INT(instance->thread_data_table, &thread_id, thread_data);
Expand Down
1 change: 0 additions & 1 deletion dependencies/nDPIsrvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def setColorByString(string):
global USE_COLORAMA
if USE_COLORAMA is True:
fg_color, bg_color = TermColor.getColorsByHash(string)
color_hash = TermColor.calcColorHash(string)
return '{}{}{}{}{}'.format(Style.BRIGHT, fg_color, bg_color, string, Style.RESET_ALL)
else:
return '{}{}{}'.format(TermColor.BOLD, string, TermColor.END)
Expand Down
12 changes: 7 additions & 5 deletions examples/c-analysed/c-analysed.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ static int analysed_map_to_stat(char const * const token_str,
struct global_map const * const map,
size_t map_length)
{
size_t i, null_i = map_length;
size_t i;
size_t null_i = map_length;

for (i = 0; i < map_length; ++i)
{
Expand All @@ -621,7 +622,7 @@ static int analysed_map_to_stat(char const * const token_str,
return 1;
}

static int analysed_map_value_to_stat(struct nDPIsrvd_socket * const sock,
static int analysed_map_value_to_stat(struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_json_token const * const token,
struct global_map const * const map,
size_t map_length)
Expand All @@ -638,7 +639,7 @@ static int analysed_map_value_to_stat(struct nDPIsrvd_socket * const sock,
return analysed_map_to_stat(value_str, value_length, map, map_length);
}

static void analysed_unmap_flow_from_stat(struct flow_user_data * const flow_user_data)
static void analysed_unmap_flow_from_stat(struct flow_user_data const * const flow_user_data)
{
if (flow_user_data->is_ip4 != 0)
{
Expand Down Expand Up @@ -774,7 +775,7 @@ static ssize_t analysed_map_index(char const * const json_key,
return unknown_key;
}

static int analysed_map_flow_u8(struct nDPIsrvd_socket * const sock,
static int analysed_map_flow_u8(struct nDPIsrvd_socket const * const sock,
struct nDPIsrvd_json_token const * const token,
struct global_map const * const map,
size_t map_length,
Expand Down Expand Up @@ -1975,7 +1976,8 @@ static int mainloop(int epollfd, struct nDPIsrvd_socket * const sock)

int main(int argc, char ** argv)
{
int retval = 1, epollfd = -1;
int retval = 1;
int epollfd = -1;

init_logging("nDPIsrvd-analysed");

Expand Down
6 changes: 3 additions & 3 deletions examples/c-captured/c-captured.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void decode_base64(pcap_dumper_t * const pd,
static void packet_data_copy(void * dst, const void * src)
{
struct packet_data * const pd_dst = (struct packet_data *)dst;
struct packet_data const * const pd_src = (struct packet_data *)src;
struct packet_data const * const pd_src = (struct packet_data const *)src;
*pd_dst = *pd_src;
if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0)
{
Expand All @@ -224,7 +224,7 @@ static void packet_data_dtor(void * elt)
static void flow_packet_data_copy(void * dst, const void * src)
{
struct flow_packet_data * const pd_dst = (struct flow_packet_data *)dst;
struct flow_packet_data const * const pd_src = (struct flow_packet_data *)src;
struct flow_packet_data const * const pd_src = (struct flow_packet_data const *)src;
*pd_dst = *pd_src;
if (pd_src->base64_packet != NULL && pd_src->base64_packet_size > 0)
{
Expand Down Expand Up @@ -1175,7 +1175,7 @@ static int parse_options(int argc, char ** argv)
break;
case 'R':
{
char * value = (optarg[0] == '~' ? optarg + 1 : optarg);
char const * const value = (optarg[0] == '~' ? optarg + 1 : optarg);
nDPIsrvd_ull risk;
if (perror_ull(str_value_to_ull(value, &risk), "process_risky") != CONVERSION_OK)
{
Expand Down
2 changes: 1 addition & 1 deletion nDPId-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ static void usage(char const * const arg0)
fprintf(stderr, "usage: %s [path-to-pcap-file] [optional-nDPId-config-file]\n", arg0);
}

static int thread_wait_for_termination(pthread_t thread, time_t wait_time_secs, struct thread_return_value * const trv)
static int thread_wait_for_termination(pthread_t thread, time_t wait_time_secs, struct thread_return_value * trv)
{
#if !defined(__FreeBSD__) && !defined(__APPLE__)
struct timespec ts;
Expand Down

0 comments on commit c84c52e

Please sign in to comment.