There is a segment of code that's incorrect here that can cause crashes:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
{
switch(eventCode)
{
case NSStreamEventHasBytesAvailable:
{
uint8_t buf[1024];
memset(buf, 0, sizeof(uint8_t) * 1024);
unsigned int len = 0;
len = [(NSInputStream *)stream read:buf maxLength:1024];
if(len) {
The documentation for read:maxLength: says it can return a negative number on
failure. So len should be signed, and the if statement modified:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
{
switch(eventCode)
{
case NSStreamEventHasBytesAvailable:
{
uint8_t buf[1024];
memset(buf, 0, sizeof(uint8_t) * 1024);
NSInteger len = 0;
len = [(NSInputStream *)stream read:buf maxLength:1024];
if(len > 0)
Original issue reported on code.google.com by guardian...@gmail.com on 30 Jun 2011 at 2:16
Original issue reported on code.google.com by
guardian...@gmail.com
on 30 Jun 2011 at 2:16