[mw-devel] MW3 r1268 - trunk/src

arthur at sucs.org arthur at sucs.org
Mon Nov 5 11:03:28 GMT 2012


Author: arthur
Date: 2012-11-05 11:03:28 +0000 (Mon, 05 Nov 2012)
New Revision: 1268

Modified:
   trunk/src/socket.c
Log:
make message body a valid C string by always having a trailing nul


Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2012-11-05 10:07:34 UTC (rev 1267)
+++ trunk/src/socket.c	2012-11-05 11:03:28 UTC (rev 1268)
@@ -8,11 +8,13 @@
 #include <netdb.h>
 #include "socket.h"
 
+/* generate FOURCC code from a string */
 inline unsigned int FOURCC(char *a)
 {
-	        return ((a[3]<<24)|(a[2]<<16)|(a[1]<<8)|a[0]);
+	return ((a[3]<<24)|(a[2]<<16)|(a[1]<<8)|a[0]);
 }
 
+/* create an empty message */
 ipc_message_t * ipcmsg_create(uint32_t type, uint32_t src)
 {
 	ipc_message_t *new = malloc(sizeof(ipc_message_t));
@@ -22,21 +24,25 @@
 	return new;
 }
 
+/* add body text to a message, +1 to make C string safe */
 void ipcmsg_append(ipc_message_t *msg, const char * data, int len)
 {
 	if (msg == NULL) return;
-	int want = msg->bodylen + len;
+	int want = msg->bodylen + len + 1;
 	msg->body = realloc(msg->body, want);
 	memcpy(&msg->body[msg->bodylen], data, len);
 	msg->bodylen += len;
+	msg->body[ msg->bodylen ] = 0;
 }
 
+/* set the destination (PID) of a message */
 void ipcmsg_destination(ipc_message_t *msg, uint32_t dest)
 {
 	if (msg == NULL) return;
 	msg->head.dst = dest;
 }
 
+/* free a message */
 void ipcmsg_destroy(ipc_message_t * msg)
 {
 	if (msg->body) free(msg->body);
@@ -44,6 +50,7 @@
 	free(msg);
 }
 
+/* immediately transmit a message to a socket */
 void ipcmsg_send(ipc_message_t *msg, ipc_connection_t *conn)
 {
 	struct iovec iov[2];
@@ -72,12 +79,14 @@
 	}
 }
 
+/* mark this socket as bad/gone */
 void ipcconn_bad(ipc_connection_t * conn)
 {
 	close(conn->fd);
 	conn->fd = -1;
 }
 
+/* create an empty connection socket struct */
 ipc_connection_t * ipcconn_create(void)
 {
 	ipc_connection_t * conn = malloc(sizeof(ipc_connection_t));
@@ -87,6 +96,7 @@
 	return conn;
 }
 
+/* open a tcp socket, returning the fd */
 int ipcconn_connect(const char * target)
 {
 	struct addrinfo hint;




More information about the mw-devel mailing list