mardi 30 juin 2015

How to add an int at the end of an uint8_t*?


I have a variable :

uint8_t* data

And I want to add a header to these data. Exactly two numbers. I want my data like these : data+my_int+my_second_int

After that I have to give my data to a function (that I can't modify), and the size of my data.

Like this : myfunction(data,size);

This is currently what my code looks like :

struct Data {
  uin8_t* data;
  uint32_t PTS;
  uint32_t DTS;
  uint16_t size_data;
};


struct Data* mydata;
mydata->data = data; // data I get before
mydata->size_daza = size; // size I get before
mydata->PTS = GST_BUFFER_PTS(buf);
mydata->DTS = GST_BUFFER_DTS(buf);

myfunction(mydata,sizeof(struct Data)); // My function , this function add also a header to my data (another).I can't access or modify this function.

After this, multiple things happend (doesn't matter what) and at the end another function delete the header appended with 'myfunction',then I cast the data given by this function in struct Data*. I can access to DTS, PTS , size but I have a SIGSEGV error on the data..

I think I have to change my Structure but i don't see an other manner to store a buffer without a pointer.


Aucun commentaire:

Enregistrer un commentaire