aboutsummaryrefslogtreecommitdiffstats
path: root/capture_sync.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-12-26 05:57:06 +0000
committerGuy Harris <guy@alum.mit.edu>2012-12-26 05:57:06 +0000
commit8ed7a73e22c049a2e013bb436e599bff41fc5b9b (patch)
treead4a4cc6fb4ff4d3e3ffe3a3f8e3d056e441ae46 /capture_sync.c
parent8ede6b7dc09aa636f87147ab432a137c209e8aca (diff)
Fix a bunch of warnings.
Cast away some implicit 64-bit-to-32-bit conversion errors due to use of sizeof. Cast away some implicit 64-bit-to-32-bit conversion errors due to use of strtol() and strtoul(). Change some data types to avoid those implicit conversion warnings. When assigning a constant to a float, make sure the constant isn't a double, by appending "f" to the constant. Constify a bunch of variables, parameters, and return values to eliminate warnings due to strings being given const qualifiers. Cast away those warnings in some cases where an API we don't control forces us to do so. Enable a bunch of additional warnings by default. Note why at least some of the other warnings aren't enabled. randpkt.c and text2pcap.c are used to build programs, so they don't need to be in EXTRA_DIST. If the user specifies --enable-warnings-as-errors, add -Werror *even if the user specified --enable-extra-gcc-flags; assume they know what they're doing and are willing to have the compile fail due to the extra GCC warnings being treated as errors. svn path=/trunk/; revision=46748
Diffstat (limited to 'capture_sync.c')
-rw-r--r--capture_sync.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/capture_sync.c b/capture_sync.c
index 1020f18fdb..d3de9994cd 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -115,7 +115,7 @@ static const char *sync_pipe_signame(int);
static gboolean sync_pipe_input_cb(gint source, gpointer user_data);
static int sync_pipe_wait_for_child(int fork_child, gchar **msgp);
static void pipe_convert_header(const guchar *header, int header_len, char *indicator, int *block_len);
-static int pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
+static ssize_t pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
char **err_msg);
@@ -949,7 +949,7 @@ sync_pipe_run_command(const char** argv, gchar **data, gchar **primary_msg,
int data_pipe_read_fd, sync_pipe_read_fd, fork_child, ret;
char *wait_msg;
gchar buffer[PIPE_BUF_SIZE+1];
- int nread;
+ ssize_t nread;
char indicator;
int primary_msg_len;
char *primary_msg_text;
@@ -957,7 +957,7 @@ sync_pipe_run_command(const char** argv, gchar **data, gchar **primary_msg,
char *secondary_msg_text;
char *combined_msg;
GString *data_buf = NULL;
- int count;
+ size_t count;
ret = sync_pipe_open_command(argv, &data_pipe_read_fd, &sync_pipe_read_fd,
&fork_child, &msg);
@@ -1262,7 +1262,7 @@ sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg)
int message_read_fd, ret;
char *wait_msg;
gchar buffer[PIPE_BUF_SIZE+1];
- int nread;
+ ssize_t nread;
char indicator;
int primary_msg_len;
char *primary_msg_text;
@@ -1416,11 +1416,11 @@ sync_interface_stats_close(int *read_fd, int *fork_child, gchar **msg)
/* read a number of bytes from a pipe */
/* (blocks until enough bytes read or an error occurs) */
-static int
+static ssize_t
pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg)
{
- int newly;
- int offset = 0;
+ ssize_t newly;
+ ssize_t offset = 0;
int error;
while(required) {
@@ -1443,7 +1443,7 @@ pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg)
return newly;
}
- required -= newly;
+ required -= (int)newly;
offset += newly;
}
@@ -1484,7 +1484,7 @@ static gboolean pipe_data_available(int pipe_fd) {
/* Read a line from a pipe, similar to fgets */
int
sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
- int newly;
+ ssize_t newly;
int offset = -1;
while(offset < max - 1) {
@@ -1495,11 +1495,11 @@ sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
if (newly == 0) {
/* EOF - not necessarily an error */
break;
- } else if (newly < 0) {
+ } else if (newly == -1) {
/* error */
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"read from pipe %d: error(%u): %s", pipe_fd, errno, g_strerror(errno));
- return newly;
+ return -1;
} else if (bytes[offset] == '\n') {
break;
}
@@ -1526,12 +1526,12 @@ pipe_convert_header(const guchar *header, int header_len, char *indicator, int *
/* read a message from the sending pipe in the standard format
(1-byte message indicator, 3-byte message length (excluding length
and indicator field), and the rest is the message) */
-static int
+static ssize_t
pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
char **err_msg)
{
int required;
- int newly;
+ ssize_t newly;
guchar header[4];
/* read header (indicator and 3-byte length) */
@@ -1548,13 +1548,13 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
return 0;
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
- "read %d failed to read header: %u", pipe_fd, newly);
+ "read %d failed to read header: %lu", pipe_fd, (long)newly);
if (newly != -1) {
/*
* Short read, but not an immediate EOF.
*/
- *err_msg = g_strdup_printf("Premature EOF reading from sync pipe: got only %d bytes",
- newly);
+ *err_msg = g_strdup_printf("Premature EOF reading from sync pipe: got only %ld bytes",
+ (long)newly);
}
return -1;
}
@@ -1617,13 +1617,14 @@ sync_pipe_input_cb(gint source, gpointer user_data)
capture_options *capture_opts = (capture_options *)user_data;
int ret;
char buffer[SP_MAX_MSG_LEN+1];
- int nread;
+ ssize_t nread;
char indicator;
int primary_len;
char *primary_msg;
int secondary_len;
char *secondary_msg;
char *wait_msg, *combined_msg;
+ int npackets;
nread = pipe_read_block(source, &indicator, SP_MAX_MSG_LEN, buffer,
&primary_msg);
@@ -1701,9 +1702,9 @@ sync_pipe_input_cb(gint source, gpointer user_data)
}
break;
case SP_PACKET_COUNT:
- nread = atoi(buffer);
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
- capture_input_new_packets(capture_opts, nread);
+ npackets = atoi(buffer);
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", npackets);
+ capture_input_new_packets(capture_opts, npackets);
break;
case SP_ERROR_MSG:
/* convert primary message */
@@ -1817,8 +1818,8 @@ sync_pipe_wait_for_child(int fork_child, gchar **msgp)
#endif
g_get_current_time(&end_time);
- elapsed = (end_time.tv_sec - start_time.tv_sec) +
- ((end_time.tv_usec - start_time.tv_usec) / (float) 1e6);
+ elapsed = (float) ((end_time.tv_sec - start_time.tv_sec) +
+ ((end_time.tv_usec - start_time.tv_usec) / 1e6));
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: capture child closed after %.3fs", elapsed);
return ret;
}