changeset 26997:90e7220cf773

Fix two sizeof(size_t) != sizeof(unsigned int) warnings which could never actually be problematic. I also documented the maximum sizes of the reads at those lines.
author Paul Aurich <paul@darkrain42.org>
date Tue, 19 May 2009 06:40:04 +0000
parents 338ac8c43931
children bf3ad70508f4
files libpurple/protocols/jabber/si.c
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/si.c	Tue May 19 06:35:24 2009 +0000
+++ b/libpurple/protocols/jabber/si.c	Tue May 19 06:40:04 2009 +0000
@@ -441,9 +441,11 @@
 		purple_xfer_cancel_remote(xfer);
 		return;
 	} else if(jsx->rxlen - 5 <  jsx->rxqueue[4] + 2) {
-		purple_debug_info("jabber", "reading %u bytes for DST.ADDR + port num (trying to read %u now)\n",
-				  jsx->rxqueue[4] + 2, jsx->rxqueue[4] + 2 - (jsx->rxlen - 5));
-		len = read(source, buffer, jsx->rxqueue[4] + 2 - (jsx->rxlen - 5));
+		/* Upper-bound of 257 (jsx->rxlen = 5, jsx->rxqueue[4] = 0xFF) */
+		unsigned short to_read = jsx->rxqueue[4] + 2 - (jsx->rxlen - 5);
+		purple_debug_info("jabber", "reading %u bytes for DST.ADDR + port num (trying to read %hu now)\n",
+				  jsx->rxqueue[4] + 2, to_read);
+		len = read(source, buffer, to_read);
 		if(len < 0 && errno == EAGAIN)
 			return;
 		else if(len <= 0) {
@@ -586,10 +588,12 @@
 		memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
 		jsx->rxlen += len;
 		return;
-	} else if(jsx->rxlen - 2 <  jsx->rxqueue[1]) {
-		purple_debug_info("jabber", "reading %u bytes for auth methods (trying to read %u now)\n",
-				  jsx->rxqueue[1], jsx->rxqueue[1] - (jsx->rxlen - 2));
-		len = read(source, buffer, jsx->rxqueue[1] - (jsx->rxlen - 2));
+	} else if(jsx->rxlen - 2 < jsx->rxqueue[1]) {
+		/* Has a maximum value of 255 (jsx->rxlen = 2, jsx->rxqueue[1] = 0xFF) */
+		unsigned short to_read = jsx->rxqueue[1] - (jsx->rxlen - 2);
+		purple_debug_info("jabber", "reading %u bytes for auth methods (trying to read %hu now)\n",
+				  jsx->rxqueue[1], to_read);
+		len = read(source, buffer, to_read);
 		if(len < 0 && errno == EAGAIN)
 			return;
 		else if(len <= 0) {