changeset 30850:9d028dbd76f4

Change the "length of bstream" data type to be a gsize, since it represents the size of a buffer. There's no reason this should ever be negative. It probably shouldn't be more than 32 bits, either, but gsize still seems more appropriate to me
author Mark Doliner <mark@kingant.net>
date Sun, 15 Aug 2010 08:42:30 +0000
parents 6ee64d62c43c
children 8b94ce420e01
files libpurple/protocols/oscar/bstream.c libpurple/protocols/oscar/odc.c libpurple/protocols/oscar/oscar.h libpurple/protocols/oscar/peer_proxy.c
diffstat 4 files changed, 25 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/bstream.c	Sat Aug 14 06:24:04 2010 +0000
+++ b/libpurple/protocols/oscar/bstream.c	Sun Aug 15 08:42:30 2010 +0000
@@ -24,7 +24,7 @@
 
 #include "oscar.h"
 
-int byte_stream_new(ByteStream *bs, guint32 len)
+int byte_stream_new(ByteStream *bs, size_t len)
 {
 	if (bs == NULL)
 		return -1;
@@ -32,7 +32,7 @@
 	return byte_stream_init(bs, g_malloc(len), len);
 }
 
-int byte_stream_init(ByteStream *bs, guint8 *data, int len)
+int byte_stream_init(ByteStream *bs, guint8 *data, size_t len)
 {
 	if (bs == NULL)
 		return -1;
@@ -59,7 +59,7 @@
 	return bs->offset;
 }
 
-int byte_stream_setpos(ByteStream *bs, unsigned int off)
+int byte_stream_setpos(ByteStream *bs, size_t off)
 {
 	g_return_val_if_fail(off <= bs->len, -1);
 
@@ -133,13 +133,13 @@
 	return aimutil_getle32(bs->data + bs->offset - 4);
 }
 
-static void byte_stream_getrawbuf_nocheck(ByteStream *bs, guint8 *buf, int len)
+static void byte_stream_getrawbuf_nocheck(ByteStream *bs, guint8 *buf, size_t len)
 {
 	memcpy(buf, bs->data + bs->offset, len);
 	bs->offset += len;
 }
 
-int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len)
+int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, size_t len)
 {
 	g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0);
 
@@ -147,7 +147,7 @@
 	return len;
 }
 
-guint8 *byte_stream_getraw(ByteStream *bs, int len)
+guint8 *byte_stream_getraw(ByteStream *bs, size_t len)
 {
 	guint8 *ob;
 
@@ -158,7 +158,7 @@
 	return ob;
 }
 
-char *byte_stream_getstr(ByteStream *bs, int len)
+char *byte_stream_getstr(ByteStream *bs, size_t len)
 {
 	char *ob;
 
@@ -219,7 +219,7 @@
 }
 
 
-int byte_stream_putraw(ByteStream *bs, const guint8 *v, int len)
+int byte_stream_putraw(ByteStream *bs, const guint8 *v, size_t len)
 {
 	g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0);
 
@@ -233,7 +233,7 @@
 	return byte_stream_putraw(bs, (guint8 *)str, strlen(str));
 }
 
-int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, int len)
+int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, size_t len)
 {
 	g_return_val_if_fail(byte_stream_bytes_left(srcbs) >= len, 0);
 	g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0);
--- a/libpurple/protocols/oscar/odc.c	Sat Aug 14 06:24:04 2010 +0000
+++ b/libpurple/protocols/oscar/odc.c	Sun Aug 15 08:42:30 2010 +0000
@@ -90,7 +90,7 @@
 	ByteStream bs;
 
 	purple_debug_info("oscar", "Outgoing ODC frame to %s with "
-		"type=0x%04x, flags=0x%04x, payload length=%u\n",
+		"type=0x%04x, flags=0x%04x, payload length=%" G_GSIZE_FORMAT "\n",
 		conn->bn, frame->type, frame->flags, frame->payload.len);
 
 	account = purple_connection_get_account(conn->od->gc);
@@ -505,7 +505,7 @@
 	byte_stream_getrawbuf(bs, frame->bn, 32);
 
 	purple_debug_info("oscar", "Incoming ODC frame from %s with "
-			"type=0x%04x, flags=0x%04x, payload length=%u\n",
+			"type=0x%04x, flags=0x%04x, payload length=%" G_GSIZE_FORMAT "\n",
 			frame->bn, frame->type, frame->flags, frame->payload.len);
 
 	if (!conn->ready)
--- a/libpurple/protocols/oscar/oscar.h	Sat Aug 14 06:24:04 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.h	Sun Aug 15 08:42:30 2010 +0000
@@ -238,8 +238,8 @@
 struct _ByteStream
 {
 	guint8 *data;
-	guint32 len;
-	guint32 offset;
+	size_t len;
+	size_t offset;
 };
 
 struct _QueuedSnac
@@ -1209,12 +1209,12 @@
 void aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *);
 
 /* bstream.c */
-int byte_stream_new(ByteStream *bs, guint32 len);
-int byte_stream_init(ByteStream *bs, guint8 *data, int len);
+int byte_stream_new(ByteStream *bs, size_t len);
+int byte_stream_init(ByteStream *bs, guint8 *data, size_t len);
 void byte_stream_destroy(ByteStream *bs);
 int byte_stream_bytes_left(ByteStream *bs);
 int byte_stream_curpos(ByteStream *bs);
-int byte_stream_setpos(ByteStream *bs, unsigned int off);
+int byte_stream_setpos(ByteStream *bs, size_t off);
 void byte_stream_rewind(ByteStream *bs);
 int byte_stream_advance(ByteStream *bs, int n);
 guint8 byte_stream_get8(ByteStream *bs);
@@ -1223,18 +1223,18 @@
 guint8 byte_stream_getle8(ByteStream *bs);
 guint16 byte_stream_getle16(ByteStream *bs);
 guint32 byte_stream_getle32(ByteStream *bs);
-int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len);
-guint8 *byte_stream_getraw(ByteStream *bs, int len);
-char *byte_stream_getstr(ByteStream *bs, int len);
+int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, size_t len);
+guint8 *byte_stream_getraw(ByteStream *bs, size_t len);
+char *byte_stream_getstr(ByteStream *bs, size_t len);
 int byte_stream_put8(ByteStream *bs, guint8 v);
 int byte_stream_put16(ByteStream *bs, guint16 v);
 int byte_stream_put32(ByteStream *bs, guint32 v);
 int byte_stream_putle8(ByteStream *bs, guint8 v);
 int byte_stream_putle16(ByteStream *bs, guint16 v);
 int byte_stream_putle32(ByteStream *bs, guint32 v);
-int byte_stream_putraw(ByteStream *bs, const guint8 *v, int len);
+int byte_stream_putraw(ByteStream *bs, const guint8 *v, size_t len);
 int byte_stream_putstr(ByteStream *bs, const char *str);
-int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, int len);
+int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, size_t len);
 int byte_stream_putuid(ByteStream *bs, OscarData *od);
 int byte_stream_putcaps(ByteStream *bs, guint64 caps);
 
--- a/libpurple/protocols/oscar/peer_proxy.c	Sat Aug 14 06:24:04 2010 +0000
+++ b/libpurple/protocols/oscar/peer_proxy.c	Sun Aug 15 08:42:30 2010 +0000
@@ -32,8 +32,8 @@
 	ByteStream bs;
 
 	purple_debug_info("oscar", "Outgoing peer proxy frame with "
-			"type=0x%04hx, unknown=0x%08x, "
-			"flags=0x%04hx, and payload length=%hd\n",
+			"type=0x%04hx, unknown=0x%08x, flags=0x%04hx, and "
+			"payload length=%" G_GSIZE_FORMAT "\n",
 			frame->type, frame->unknown,
 			frame->flags, frame->payload.len);
 
@@ -129,8 +129,8 @@
 peer_proxy_recv_frame(PeerConnection *conn, ProxyFrame *frame)
 {
 	purple_debug_info("oscar", "Incoming peer proxy frame with "
-			"type=0x%04hx, unknown=0x%08x, "
-			"flags=0x%04hx, and payload length=%hd\n", frame->type,
+			"type=0x%04hx, unknown=0x%08x, flags=0x%04hx, and "
+			"payload length=%" G_GSIZE_FORMAT "\n", frame->type,
 			frame->unknown, frame->flags, frame->payload.len);
 
 	if (frame->type == PEER_PROXY_TYPE_CREATED)