fix multiple conversion errors and remove compilation warnings

This commit is contained in:
Kaian 2018-04-21 13:10:02 +02:00
parent 4a221fc567
commit aadd3e4d78
15 changed files with 30 additions and 23 deletions

View File

@ -6,6 +6,7 @@ project(sngrep
set(PROJECT_NAME sngrep)
set(CMAKE_C_STANDARD 99)
add_compile_options(-Werror)
#add_compile_options(-Werror -Wall -pedantic -Wextra)
configure_file(
${PROJECT_SOURCE_DIR}/src/config.h.cmake.in

View File

@ -81,7 +81,7 @@ capture_manager_start(CaptureManager *manager)
for (GSList *le = manager->inputs; le != NULL; le = le->next) {
CaptureInput *input = le->data;
input->running = TRUE;
input->thread = g_thread_new(NULL, (void *) input->start, input);
input->thread = g_thread_new(NULL, (GThreadFunc) input->start, input);
}
}
@ -132,7 +132,7 @@ capture_manager_filter(CaptureManager *manager)
}
void
capture_manager_set_keyfile(CaptureManager *manager, gchar *keyfile, GError **error)
capture_manager_set_keyfile(CaptureManager *manager, gchar *keyfile, G_GNUC_UNUSED GError **error)
{
manager->keyfile = keyfile;
}

View File

@ -85,7 +85,7 @@ capture_input_pcap_online(const gchar *dev, GError **error)
pcap->link = pcap_datalink(pcap->handle);
// Check linktypes sngrep knowns before start parsing packets
if (proto_link_size(pcap->link) == -1) {
if (proto_link_size(pcap->link) == 0) {
g_set_error (error,
CAPTURE_PCAP_ERROR,
CAPTURE_PCAP_ERROR_UNKNOWN_LINK,
@ -142,7 +142,7 @@ capture_input_pcap_offline(const gchar *infile, GError **error)
pcap->link = pcap_datalink(pcap->handle);
// Check linktypes sngrep knowns before start parsing packets
if (proto_link_size(pcap->link) == -1) {
if (proto_link_size(pcap->link) == 0) {
g_set_error (error,
CAPTURE_PCAP_ERROR,
CAPTURE_PCAP_ERROR_UNKNOWN_LINK,
@ -307,11 +307,9 @@ capture_pcap_parse_packet(u_char *info, const struct pcap_pkthdr *header, const
// Capture Input info
CaptureInput *input = (CaptureInput *) info;
// Capture pcap info
CapturePcap *pcap = input->priv;
// Capture manager
CaptureManager *manager = input->manager;
//
// Packet dissectors parser
PacketParser *parser = input->parser;
// Ignore packets while capture is paused

View File

@ -430,7 +430,7 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline)
Address src;
Address dst;
char method[80];
char delta[15] = { };
char delta[15] = { 0 };
int flowh;
char mediastr[40];
SipMsg *msg = arrow->item;

View File

@ -160,7 +160,7 @@ call_list_info(ui_t *ui)
}
bool
call_list_redraw(ui_t *ui)
call_list_redraw(G_GNUC_UNUSED ui_t *ui)
{
return storage_calls_changed();
}

View File

@ -105,7 +105,7 @@ address_is_local(Address addr)
Address
address_from_str(const char *ipport)
{
Address ret = {};
Address ret = { 0 };
gchar scanipport[256];
gchar address[256];
guint16 port;
@ -115,7 +115,7 @@ address_from_str(const char *ipport)
strncpy(scanipport, ipport, strlen(ipport));
if (sscanf(scanipport, "%[^:]:%hd", address, &port) == 2) {
if (sscanf(scanipport, "%[^:]:%hu", address, &port) == 2) {
strncpy(ret.ip, address, strlen(address));
ret.port = port;
}

View File

@ -195,6 +195,8 @@ packet_ip_parse(PacketParser *parser, Packet *packet, GByteArray *data)
// Call next dissector
return packet_parser_next_dissector(parser, packet, data);
}
return data;
}
static void

View File

@ -45,7 +45,7 @@ packet_link_parse(PacketParser *parser, Packet *packet, GByteArray *data)
g_return_val_if_fail(priv, NULL);
// Get Layer header size from link type
gint offset = priv->link_size;
guint offset = (guint) priv->link_size;
// For ethernet, skip VLAN header if present
if (priv->link_type == DLT_EN10MB) {
@ -162,7 +162,7 @@ packet_link_init(PacketParser *parser)
}
static void
packet_link_deinit(PacketParser *parser)
packet_link_deinit(G_GNUC_UNUSED PacketParser *parser)
{
// g_free(proto->priv);
// g_free(proto);

View File

@ -91,7 +91,7 @@ packet_rtcp_parse(G_GNUC_UNUSED PacketParser *parser, Packet *packet, GByteArray
break;
// Header length
gint hlen = g_ntohs(hdr.len) * 4 + 4;
guint hlen = (guint) g_ntohs(hdr.len) * 4 + 4;
// No enough data for this RTCP header
if (hlen > data->len)
@ -117,7 +117,7 @@ packet_rtcp_parse(G_GNUC_UNUSED PacketParser *parser, Packet *packet, GByteArray
size_t bsize = sizeof(hdr_xr);
// Read all report blocks
while (bsize < ntohs(hdr_xr.len) * 4 + 4) {
while (bsize < (guint) ntohs(hdr_xr.len) * 4 + 4) {
// Read block header
memcpy(&blk_xr, data->data + bsize, sizeof(blk_xr));
// Check block type

View File

@ -227,6 +227,8 @@ packet_sdp_dissect(G_GNUC_UNUSED PacketParser *parser, Packet *packet, GByteArra
// Set packet SDP data
g_ptr_array_insert(packet->proto, PACKET_SDP, sdp);
return data;
}
PacketDissector *

View File

@ -172,14 +172,14 @@ packet_sip_parse(PacketParser *parser, Packet *packet, GByteArray *data)
gint start, end;
// Only handle UTF-8 SIP payloads
if (!g_utf8_validate(data->data, data->len, NULL)) {
if (!g_utf8_validate((gchar *) data->data, data->len, NULL)) {
return data;
}
DissectorSipData *sip = g_ptr_array_index(parser->dissectors, PACKET_SIP);
// Convert payload to something we can parse with regular expressions
GString *payload = g_string_new_len(data->data, data->len);
GString *payload = g_string_new_len((const gchar *) data->data, data->len);
// If this comes from a TCP stream, check we have a whole packet
if (packet_has_type(packet, PACKET_TCP)) {
@ -204,14 +204,14 @@ packet_sip_parse(PacketParser *parser, Packet *packet, GByteArray *data)
g_match_info_fetch_pos(pmatch, 1, &start, &end);
// The SDP body of the SIP message ends in another packet
if (start + content_len > data->len) {
if ((guint) (start + content_len) > data->len) {
g_match_info_free(pmatch);
// Not a SIP message or not complete
return data;
}
// We got more than one SIP message in the same packet
if (start + content_len < data->len) {
if ((guint) (start + content_len) < data->len) {
// Limit the size of the string to the end of the body
g_string_set_size(payload, start + content_len);
}

View File

@ -248,6 +248,8 @@ packet_tcp_parse(PacketParser *parser, Packet *packet, GByteArray *data)
} else if (pending->len < data->len) {
// Partially parsed
}
return pending;
}
static void

View File

@ -33,8 +33,8 @@
*
*/
#ifndef __SNGREP_CAPTURE_PACKET_H
#define __SNGREP_CAPTURE_PACKET_H
#ifndef __SNGREP_CAPTURE_OLD_PACKET_H
#define __SNGREP_CAPTURE_OLD_PACKET_H
#include <time.h>
#include <sys/types.h>
@ -173,4 +173,4 @@ packet_payload(packet_t *packet);
struct timeval
packet_time(const packet_t *packet);
#endif /* __SNGREP_CAPTURE_PACKET_H */
#endif /* __SNGREP_CAPTURE_OLD_PACKET_H */

View File

@ -144,7 +144,7 @@ packet_to_oldpkt(Packet *packet)
PacketSipData *sipdata = g_ptr_array_index(packet->proto, PACKET_SIP);
if (sipdata) {
packet_set_payload(oldpkt, sipdata->payload, strlen(sipdata->payload));
packet_set_payload(oldpkt, (guchar *) sipdata->payload, strlen(sipdata->payload));
}
oldpkt->frames = g_sequence_new(NULL);

View File

@ -113,6 +113,8 @@ packet_parser_add_proto(PacketParser *parser, GNode *parent, enum packet_proto i
for (GSList *l = dissector->subdissectors; l != NULL; l = l->next) {
packet_parser_add_proto(parser, node, GPOINTER_TO_UINT(l->data));
}
return dissector;
}