From 5757b130558cc2314bcd31e0e75cc4ed2edcfecb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 4 Aug 2007 19:24:58 -0700 Subject: [PATCH] Use memset() on some of the char[]'s to make sure we don't have problems with memory * Source/SocketWrapper.m: ([SocketWrapper receive:]): Set the packetLength char array and the packet char array to be null before writing into them --- Source/SocketWrapper.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 33a6d4e..bdf58c0 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -220,6 +220,7 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; // strip the length from the packet, and clear the null byte then add it to the NSData char packetLength[8]; + memset(packetLength, '\0', sizeof(packetLength)); int i = 0; while (buffer[i] != '\0') { @@ -235,10 +236,11 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; // move the packet part of the received data into it's own char[] char packet[sizeof(buffer)]; + memset(packet, '\0', sizeof(packet)); memmove(packet, &buffer[i], recvd - i); // convert bytes to NSData - [data appendBytes: packet length: recvd]; + [data appendBytes: packet length: recvd - i]; // check if we have a partial packet if (length + i > sizeof(buffer)) @@ -256,6 +258,8 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; } } + NSLog(@"data = %@", [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]); + if (selector != nil) { [self postNotification: NsockDataReceived -- 2.22.5