c++ - segmentation fault and array issue -


i've been going trying find segmentation error in program. when program crashes @ point.

unsigned long data = octets[g]; 

so have tracked buffer being created in main loop fixed defined size. since it's defined in if statement in main need allocated "new"? after receiving tcp socket char buffer copied unsigned char buffer check binary data types. if data arrives called existance.

int8u bytearray[buffersize]; 

this buffer passed message id , crc checking. not doing "new" type allocation issue because in main loop? thought go out of scope @ end of "if new data received" statement.

long calc_crc24q(byte* octets, int start, int last) //start first byte, last msbyte of crc {   long crc = crc24seed;   for(int g = start; g < last; g++) //should xor preamble end of data   {     unsigned long data = octets[g]; //fault occurs here     crc =  crc ^ data << 16;     (int = 0; < 8; i++)     {       crc <<= 1;       if (crc & 0x1000000)       crc = crc ^ crc24poly; }   }   return crc & 0x00ffffff; //returns int value high byte 00 data in lower 3 bytes } //--------------------------------------------- 

here message id

unsigned int id_message(int8u* buffer, unsigned int posstart, unsigned int numberbytes, unsigned int& messagelength) { unsigned int messid = 0; unsigned int posend; unsigned int nobytes = 0;  if(buffer[posstart] == preamble) {     unsigned int datalength = (((0x0000 | buffer[posstart+1]) << 8) | buffer[posstart+2]);  //0x byte1  byte2     messid = ((0x0000 | (buffer[posstart+3] << 4)) | ((buffer[posstart+4] >> 4) & 0x0f)); //byte1 shift 4 bits add upper 4 bits of byte 2     nobytes = datalength + 6;     //numberbytes = nobytes;              posend = posstart + nobytes - 1;             if(calc_crc24q( buffer, posstart, posend-2) != (((0x00000000 | buffer[posend-2]) << 16) | ((0x00000000 | buffer[posend-1]) << 8) | (0x00000000 | buffer[posend])) )     {         cout << "crc error" << endl;         return 0;     }      //return message type extracted data segment     messagelength = posstart + nobytes;     return messid; } return 255; //unknown type } 


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -