ios - [(NSInputStream *)stream read:buf maxLength:1024]; returns very huge value -


in code line

->nsinteger len = [(nsinputstream *)stream read:buf   maxlength:1024];  

i getting huge value of len method like:(18446744073709551615)

and crashes

terminating app due uncaught exception 'nsmallocexception', reason: -[nsconcretemutabledata appendbytes:length:]: unable allocate memory length (18446744073709551615)

case nsstreameventhasbytesavailable:  {    nsmutabledata* lobjreaddata = [[nsmutabledata alloc] init];  nsnumber* lnumbytesread;  uint8_t buf[1024];    nsuinteger lintreadingbufferlength = 0;  nsuinteger linttotalbufferreadedlength = 0;  nsuinteger lintpreviousbufferreadedlength = 0;  nsuinteger lintseenindex = 0;    while ([(nsinputstream*)stream hasbytesavailable])  {        lintreadingbufferlength = [(nsinputstream *)stream read:buf                                                    maxlength:1024];        // times getting huge vaqlue of lintreadingbufferlength      //18446744073709551615      //crashes here crash log -> terminating app due uncaught exception 'nsmallocexception', reason: '*** -[nsconcretemutabledata appendbytes:length:]: unable allocate memory length (18446744073709551615)'        linttotalbufferreadedlength += lintreadingbufferlength;        if(lintreadingbufferlength)      {          [lobjreaddata appendbytes:(const void *)buf                             length:lintreadingbufferlength];            // bytesread instance variable of type nsnumber.          lnumbytesread = [nsnumber numberwithinteger:                           [lnumbytesread integervalue]+lintreadingbufferlength];              nsarray* larrayofbytes = [self arrayofbytesfromdata:lobjreaddata];                (nsinteger lintindexcounter = lintpreviousbufferreadedlength; lintindexcounter < linttotalbufferreadedlength;               lintindexcounter++)          {              nsobject* lobjbyte = [larrayofbytes objectatindex:lintindexcounter];                nsstring* lstrmessage = [nsstring stringwithformat:@"%@",lobjbyte];                //doing stuff here          }            lintpreviousbufferreadedlength = linttotalbufferreadedlength;      }      else if(0 == lintreadingbufferlength)      {        }      else      {          slog(@"no buffer!");      }    }    // slog(@"--------------------------------------");    break;  } 

18446744073709551615 0xffffffffffff maximum unsigned 64-bit integer value it's equivalent of -1 64-bit signed integer.

if @ reference [nsinputstream read:maxlength:] says:

return value

a number indicating outcome of operation:

  • a positive number indicates number of bytes read;

  • 0 indicates end of buffer reached;

  • a negative number means operation failed.

so operation failed , viewing value unsigned value.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -