From 6435cad92cf732c5f82b7ac32eb8e520fc9107cf Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 4 May 2010 12:37:32 -0400 Subject: [PATCH] Replace strlen() with a loop that we can guarantee. --- Source/DebuggerConnection.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index 89fc39e..f971ce3 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -473,8 +473,9 @@ void SocketAcceptCallback(CFSocketRef socket, // been processed. while (bufferOffset < bytesRead) { - // strlen() counts to the first non-NULL character. - NSUInteger partLength = MIN(strlen(charBuffer + bufferOffset), kBufferSize - bufferOffset); + // Find the NULL separator, or the end of the string. + NSUInteger partLength = 0; + for (NSUInteger i = bufferOffset; i < bytesRead && charBuffer[i] != '\0'; ++i, ++partLength) ; // If there is not a current packet, set some state. if (!self.currentPacket) @@ -583,7 +584,7 @@ void SocketAcceptCallback(CFSocketRef socket, } if (transaction != lastWrittenTransaction_) - NSLog(@"txn %d(%d) <> %d doesn't match last written", transaction, lastReadTransaction_, lastWrittenTransaction_); + NSLog(@"txn %d <> %d last written, %d last read", transaction, lastWrittenTransaction_, lastReadTransaction_); lastReadTransaction_ = transaction; } -- 2.43.5