/pidgin/main: 5804117fb298: Fix the rest of libpurple warnings a...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Thu Aug 22 03:59:43 EDT 2013


Changeset: 5804117fb298dea7b251043ec43829598e892ee1
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-08-22 09:59 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/5804117fb298

Description:

Fix the rest of libpurple warnings about -Wsign-compare

diffstat:

 libpurple/cipher.c     |   7 +++----
 libpurple/circbuffer.c |  10 +++++-----
 libpurple/dnsquery.c   |   6 +++---
 libpurple/dnssrv.c     |   2 +-
 libpurple/ft.c         |  10 ++++++----
 libpurple/http.c       |  23 ++++++++++++++++-------
 libpurple/proxy.c      |   6 +++---
 libpurple/util.c       |   4 ++--
 8 files changed, 39 insertions(+), 29 deletions(-)

diffs (289 lines):

diff --git a/libpurple/cipher.c b/libpurple/cipher.c
--- a/libpurple/cipher.c
+++ b/libpurple/cipher.c
@@ -128,7 +128,7 @@ purple_cipher_digest_region(const gchar 
 {
 	PurpleCipher *cipher;
 	PurpleCipherContext *context;
-	ssize_t digest_size;
+	size_t digest_size;
 	gboolean succ;
 
 	g_return_val_if_fail(name, -1);
@@ -157,7 +157,7 @@ purple_cipher_digest_region(const gchar 
 	succ = purple_cipher_context_digest(context, digest, out_size);
 	purple_cipher_context_destroy(context);
 
-	return succ ? digest_size : -1;
+	return succ ? (ssize_t)digest_size : -1;
 }
 
 /******************************************************************************
@@ -453,8 +453,7 @@ purple_cipher_context_digest_to_str(Purp
 {
 	/* 8k is a bit excessive, will tweak later. */
 	guchar digest[BUF_LEN * 4];
-	gint n = 0;
-	size_t digest_size;
+	size_t digest_size, n;
 
 	g_return_val_if_fail(context, FALSE);
 	g_return_val_if_fail(digest_s, FALSE);
diff --git a/libpurple/circbuffer.c b/libpurple/circbuffer.c
--- a/libpurple/circbuffer.c
+++ b/libpurple/circbuffer.c
@@ -42,8 +42,8 @@ void purple_circ_buffer_destroy(PurpleCi
 }
 
 static void grow_circ_buffer(PurpleCircBuffer *buf, gsize len) {
-	int in_offset = 0, out_offset = 0;
-	int start_buflen;
+	gsize in_offset = 0, out_offset = 0;
+	gsize start_buflen;
 
 	g_return_if_fail(buf != NULL);
 
@@ -70,7 +70,7 @@ static void grow_circ_buffer(PurpleCircB
 	 * pointer, we need to shift the data */
 	if (in_offset < out_offset
 			|| (in_offset == out_offset && buf->bufused > 0)) {
-		int shift_n = MIN(buf->buflen - start_buflen,
+		gsize shift_n = MIN(buf->buflen - start_buflen,
 			in_offset);
 		memcpy(buf->buffer + start_buflen, buf->buffer,
 			shift_n);
@@ -92,7 +92,7 @@ static void grow_circ_buffer(PurpleCircB
 
 void purple_circ_buffer_append(PurpleCircBuffer *buf, gconstpointer src, gsize len) {
 
-	int len_stored;
+	gsize len_stored;
 
 	g_return_if_fail(buf != NULL);
 
@@ -145,7 +145,7 @@ gboolean purple_circ_buffer_mark_read(Pu
 	buf->outptr += len;
 	buf->bufused -= len;
 	/* wrap to the start if we're at the end */
-	if ((buf->outptr - buf->buffer) == buf->buflen)
+	if ((gsize)(buf->outptr - buf->buffer) == buf->buflen)
 		buf->outptr = buf->buffer;
 
 	return TRUE;
diff --git a/libpurple/dnsquery.c b/libpurple/dnsquery.c
--- a/libpurple/dnsquery.c
+++ b/libpurple/dnsquery.c
@@ -242,7 +242,7 @@ write_to_parent(int fd, const void *buf,
 	ssize_t written;
 
 	written = write(fd, buf, count);
-	if (written != count) {
+	if (written < 0 || (gsize)written != count) {
 		if (written < 0)
 			fprintf(stderr, "dns[%d]: Error writing data to "
 					"parent: %s\n", getpid(), strerror(errno));
@@ -422,7 +422,7 @@ cope_with_gdb_brokenness(void)
 	if(n < 0)
 		return;
 
-	e[MIN(n,sizeof(e)-1)] = '\0';
+	e[MIN((gsize)n,sizeof(e)-1)] = '\0';
 
 	if(strstr(e,"gdb")) {
 		purple_debug_info("dns",
@@ -555,7 +555,7 @@ send_dns_request_to_child(PurpleDnsQuery
 		purple_dnsquery_resolver_destroy(resolver);
 		return FALSE;
 	}
-	if (rc < sizeof(dns_params)) {
+	if ((gsize)rc < sizeof(dns_params)) {
 		purple_debug_error("dns", "Tried to write %" G_GSSIZE_FORMAT
 				" bytes to child but only wrote %" G_GSSIZE_FORMAT "\n",
 				sizeof(dns_params), rc);
diff --git a/libpurple/dnssrv.c b/libpurple/dnssrv.c
--- a/libpurple/dnssrv.c
+++ b/libpurple/dnssrv.c
@@ -543,7 +543,7 @@ resolved(gpointer data, gint source, Pur
 						res->content = g_new0(gchar, len);
 
 						red = read(source, res->content, len);
-						if (red != len) {
+						if (red < 0 || (gsize)red != len) {
 							purple_debug_error("dnssrv","unable to read txt "
 									"response: %s\n", g_strerror(errno));
 							size = 0;
diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -98,7 +98,7 @@ purple_xfer_status_type_to_string(Purple
 		{ PURPLE_XFER_STATUS_CANCEL_LOCAL, "cancelled locally" },
 		{ PURPLE_XFER_STATUS_CANCEL_REMOTE, "cancelled remotely" }
 	};
-	int i;
+	gsize i;
 
 	for (i = 0; i < G_N_ELEMENTS(type_names); ++i)
 		if (type_names[i].type == type)
@@ -1107,7 +1107,7 @@ purple_xfer_read(PurpleXfer *xfer, gucha
 			r = -1;
 	}
 
-	if (r == xfer->current_buffer_size)
+	if (r >= 0 && (gsize)r == xfer->current_buffer_size)
 		/*
 		 * We managed to read the entire buffer.  This means our this
 		 * network is fast and our buffer is too small, so make it
@@ -1205,7 +1205,7 @@ purple_xfer_read_file(PurpleXfer *xfer, 
 
 		got_len = ui_ops->ui_read(xfer, &buffer_got, size);
 
-		if (got_len > size) {
+		if (got_len >= 0 && (gsize)got_len > size) {
 			g_free(buffer_got);
 			purple_debug_error("filetransfer",
 				"Got too much data from UI.\n");
@@ -1224,7 +1224,9 @@ purple_xfer_read_file(PurpleXfer *xfer, 
 			return -1;
 		}
 		got_len = fread(buffer, 1, size, xfer->dest_fp);
-		if (got_len != size && ferror(xfer->dest_fp)) {
+		if ((got_len < 0 || (gsize)got_len != size) &&
+			ferror(xfer->dest_fp))
+		{
 			purple_debug_error("filetransfer",
 				"Unable to read file.\n");
 			purple_xfer_cancel_local(xfer);
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -115,7 +115,7 @@ struct _PurpleHttpConnection
 	PurpleHttpConnectionSet *connection_set;
 	PurpleHttpSocket *socket;
 	GString *request_header;
-	int request_header_written, request_contents_written;
+	guint request_header_written, request_contents_written;
 	gboolean main_header_got, headers_got;
 	GString *response_buffer;
 	PurpleHttpGzStream *gz_stream;
@@ -125,7 +125,8 @@ struct _PurpleHttpConnection
 
 	int redirects_count;
 
-	int length_expected, length_got, length_got_decompressed;
+	int length_expected;
+	guint length_got, length_got_decompressed;
 
 	gboolean is_chunked, in_chunk, chunks_done;
 	int chunk_length, chunk_got;
@@ -1065,7 +1066,7 @@ static gboolean _purple_http_recv_body_d
 	GString *decompressed = NULL;
 
 	if (hc->length_expected >= 0 &&
-		len + hc->length_got > hc->length_expected)
+		len + hc->length_got > (guint)hc->length_expected)
 	{
 		len = hc->length_expected - hc->length_got;
 	}
@@ -1246,7 +1247,7 @@ static gboolean _purple_http_recv_loopbo
 			hc->length_expected = hc->length_got;
 		}
 		if (hc->length_expected >= 0 &&
-			hc->length_got < hc->length_expected) {
+			hc->length_got < (guint)hc->length_expected) {
 			purple_debug_warning("http", "No more data while reading"
 				" contents\n");
 			_purple_http_error(hc, _("Error parsing HTTP"));
@@ -1269,6 +1270,7 @@ static gboolean _purple_http_recv_loopbo
 					"quirk)\n");
 				hc->headers_got = TRUE;
 				hc->length_expected = hc->length_got = 0;
+				hc->length_got_decompressed = 0;
 			} else {
 				purple_debug_warning("http", "No more data "
 					"while parsing headers\n");
@@ -1322,7 +1324,9 @@ static gboolean _purple_http_recv_loopbo
 	if (hc->is_chunked && hc->chunks_done && hc->length_expected < 0)
 		hc->length_expected = hc->length_got;
 
-	if (hc->length_expected >= 0 && hc->length_got >= hc->length_expected) {
+	if (hc->length_expected >= 0 &&
+		hc->length_got >= (guint)hc->length_expected)
+	{
 		const gchar *redirect;
 
 		if (hc->is_chunked && !hc->chunks_done) {
@@ -1519,8 +1523,12 @@ static void _purple_http_send(gpointer _
 		purple_http_conn_notify_progress_watcher(hc);
 		if (hc->contents_reader_buffer)
 			g_string_erase(hc->contents_reader_buffer, 0, written);
-		if (hc->request_contents_written < hc->request->contents_length)
+		if (hc->request->contents_length > 0 &&
+			hc->request_contents_written <
+			(guint)hc->request->contents_length)
+		{
 			return;
+		}
 	}
 
 	/* request is completely written, let's read the response */
@@ -1628,6 +1636,7 @@ static gboolean _purple_http_reconnect(P
 		g_string_free(hc->response->contents, TRUE);
 	hc->response->contents = NULL;
 	hc->length_got = 0;
+	hc->length_got_decompressed = 0;
 	hc->length_expected = -1;
 	hc->is_chunked = FALSE;
 	hc->in_chunk = FALSE;
@@ -2326,7 +2335,7 @@ static gboolean
 	PurpleHttpKeepaliveHost *host = _host;
 	PurpleHttpSocket *hs = NULL;
 	GSList *it;
-	int sockets_count;
+	guint sockets_count;
 
 	g_return_val_if_fail(host != NULL, FALSE);
 
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -903,7 +903,7 @@ proxy_do_write(gpointer data, gint sourc
 		purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
 		return;
 	}
-	if (ret < request_len) {
+	if ((gsize)ret < request_len) {
 		connect_data->written_len += ret;
 		return;
 	}
@@ -965,7 +965,7 @@ http_canread(gpointer data, gint source,
 	if (p != NULL) {
 		*p = '\0';
 		headers_len = (p - (char *)connect_data->read_buffer) + 4;
-	} else if(len == max_read)
+	} else if((gsize)len == max_read)
 		headers_len = len;
 	else
 		return;
@@ -1489,7 +1489,7 @@ proxy_connect_socks4(PurpleProxyConnectD
 }
 
 static gboolean
-s5_ensure_buffer_length(PurpleProxyConnectData *connect_data, int len)
+s5_ensure_buffer_length(PurpleProxyConnectData *connect_data, guint len)
 {
 	if(connect_data->read_len < len) {
 		if(connect_data->read_buf_len < len) {
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4439,8 +4439,8 @@ purple_utf8_has_word(const char *haystac
 				   ("!g_unichar_isalnum()" is not a valid way to determine word
 				    boundaries, but it is the only reasonable thing to do here),
 				   and isn't the '&' from a "&" or some such entity*/
-				(before != -2 && !g_unichar_isalnum(before) && *(p - 1) != '&')) /* XXX: what does "-2" means? */
-				&& after != -2 && !g_unichar_isalnum(after)) {
+				(before != (gunichar)-2 && !g_unichar_isalnum(before) && *(p - 1) != '&'))
+				&& after != (gunichar)-2 && !g_unichar_isalnum(after)) {
 			ret = TRUE;
 			break;
 		}



More information about the Commits mailing list